Mercurial > hg > octave-lojdl
changeset 8337:e02242c54c49
reuse matrix type detected in det
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 19 Nov 2008 16:55:47 +0100 |
parents | 9813c07ca946 |
children | a35bf360b919 |
files | liboctave/CMatrix.cc liboctave/ChangeLog liboctave/dMatrix.cc liboctave/fCMatrix.cc liboctave/fMatrix.cc src/ChangeLog src/DLD-FUNCTIONS/det.cc |
diffstat | 7 files changed, 52 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -1594,6 +1594,9 @@ { int typ = mattype.type (); + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { for (octave_idx_type i = 0; i < nc; i++) @@ -1636,7 +1639,7 @@ rcon = 0.0; for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + retval *= atmp (i,i); retval = retval.square (); }
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2008-11-19 Jaroslav Hajek <highegg@gmail.com> + + * dMatrix.cc (Matrix::determinant), + fMatrix.cc (FloatMatrix::determinant), + CMatrix.cc (ComplexMatrix::determinant), + fCMatrix.cc (FloatComplexMatrix::determinant): + Use atmp(i,i) instead of elem(i,i). + 2008-11-19 Jaroslav Hajek <highegg@gmail.com> * DET.h (base_det<T>::square): New member function.
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -1260,6 +1260,9 @@ { int typ = mattype.type (); + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { for (octave_idx_type i = 0; i < nc; i++) @@ -1302,7 +1305,7 @@ rcon = 0.0; for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + retval *= atmp (i,i); retval = retval.square (); }
--- a/liboctave/fCMatrix.cc +++ b/liboctave/fCMatrix.cc @@ -1588,6 +1588,9 @@ { int typ = mattype.type (); + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { for (octave_idx_type i = 0; i < nc; i++) @@ -1630,7 +1633,7 @@ rcon = 0.0; for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + retval *= atmp (i,i); retval = retval.square (); }
--- a/liboctave/fMatrix.cc +++ b/liboctave/fMatrix.cc @@ -1259,6 +1259,9 @@ { int typ = mattype.type (); + if (typ == MatrixType::Unknown) + typ = mattype.type (*this); + if (typ == MatrixType::Lower || typ == MatrixType::Upper) { for (octave_idx_type i = 0; i < nc; i++) @@ -1301,7 +1304,7 @@ rcon = 0.0; for (octave_idx_type i = 0; i < nc; i++) - retval *= elem (i,i); + retval *= atmp (i,i); retval = retval.square (); }
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2008-11-19 Jaroslav Hajek <highegg@gmail.com> - * DLD_FUNCTIONS/det.cc: Include only DET.h. + * DLD_FUNCTIONS/det.cc: Include only DET.h. Retrieve & matrix type & + store it after calculation if possible. 2008-11-17 John W. Eaton <jwe@octave.org>
--- a/src/DLD-FUNCTIONS/det.cc +++ b/src/DLD-FUNCTIONS/det.cc @@ -33,6 +33,15 @@ #include "oct-obj.h" #include "utils.h" +#include "ov-re-mat.h" +#include "ov-cx-mat.h" +#include "ov-flt-re-mat.h" +#include "ov-flt-cx-mat.h" + +#define MAYBE_CAST(VAR, CLASS) \ + const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \ + dynamic_cast<const CLASS *> (&arg.get_rep ()) : 0 + DEFUN_DLD (det, args, , "-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{d}, @var{rcond}] =} det (@var{a})\n\ @@ -68,6 +77,7 @@ if (arg_is_empty > 0) return octave_value (Matrix (1, 1, 1.0)); + if (nr != nc) { gripe_square_matrix_required ("det"); @@ -86,9 +96,12 @@ FloatMatrix m = arg.float_matrix_value (); if (! error_state) { - FloatDET det = m.determinant (info, rcond); + MAYBE_CAST (rep, octave_float_matrix); + MatrixType mtype = rep ? rep -> matrix_type () : MatrixType (); + FloatDET det = m.determinant (mtype, info, rcond); retval(1) = rcond; retval(0) = info == -1 ? static_cast<float>(0.0) : det.value (); + if (rep) rep->matrix_type (mtype); } } else if (arg.is_complex_type ()) @@ -100,9 +113,12 @@ FloatComplexMatrix m = arg.float_complex_matrix_value (); if (! error_state) { - FloatComplexDET det = m.determinant (info, rcond); + MAYBE_CAST (rep, octave_float_complex_matrix); + MatrixType mtype = rep ? rep -> matrix_type () : MatrixType (); + FloatComplexDET det = m.determinant (mtype, info, rcond); retval(1) = rcond; retval(0) = info == -1 ? FloatComplex (0.0) : det.value (); + if (rep) rep->matrix_type (mtype); } } } @@ -129,9 +145,12 @@ Matrix m = arg.matrix_value (); if (! error_state) { - DET det = m.determinant (info, rcond); + MAYBE_CAST (rep, octave_matrix); + MatrixType mtype = rep ? rep -> matrix_type () : MatrixType (); + DET det = m.determinant (mtype, info, rcond); retval(1) = rcond; retval(0) = info == -1 ? 0.0 : det.value (); + if (rep) rep->matrix_type (mtype); } } } @@ -156,9 +175,12 @@ ComplexMatrix m = arg.complex_matrix_value (); if (! error_state) { - ComplexDET det = m.determinant (info, rcond); + MAYBE_CAST (rep, octave_complex_matrix); + MatrixType mtype = rep ? rep -> matrix_type () : MatrixType (); + ComplexDET det = m.determinant (mtype, info, rcond); retval(1) = rcond; retval(0) = info == -1 ? Complex (0.0) : det.value (); + if (rep) rep->matrix_type (mtype); } } }