# HG changeset patch # User Jaroslav Hajek # Date 1227110147 -3600 # Node ID e02242c54c496e99ad820a6e2390cef4e09f93bc # Parent 9813c07ca946de9bd60f97968005ea1c407482b8 reuse matrix type detected in det diff --git a/liboctave/CMatrix.cc b/liboctave/CMatrix.cc --- 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 (); } diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2008-11-19 Jaroslav Hajek + + * 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 * DET.h (base_det::square): New member function. diff --git a/liboctave/dMatrix.cc b/liboctave/dMatrix.cc --- 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 (); } diff --git a/liboctave/fCMatrix.cc b/liboctave/fCMatrix.cc --- 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 (); } diff --git a/liboctave/fMatrix.cc b/liboctave/fMatrix.cc --- 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 (); } diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,6 +1,7 @@ 2008-11-19 Jaroslav Hajek - * 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 diff --git a/src/DLD-FUNCTIONS/det.cc b/src/DLD-FUNCTIONS/det.cc --- 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 (&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(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); } } }