Mercurial > hg > octave-terminal
changeset 8916:a2878ba31a9e
add diag & perm matrix query methods to octave_value
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 06 Mar 2009 12:00:11 +0100 |
parents | 485eabc0cfec |
children | d707aa3bbc36 |
files | src/ChangeLog src/DLD-FUNCTIONS/det.cc src/DLD-FUNCTIONS/inv.cc src/DLD-FUNCTIONS/pinv.cc src/ov-base-diag.h src/ov-base.cc src/ov-base.h src/ov.h |
diffstat | 8 files changed, 117 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,29 @@ +2009-03-06 Jaroslav Hajek <highegg@gmail.com> + + * ov.h (octave_value::diag_matrix_value, + octave_value::complex_diag_matrix_value, + octave_value::float_diag_matrix_value, + octave_value::float_complex_diag_matrix_value, + octave_value::perm_matrix_value): New methods. + + * ov-base.cc (octave_base_value::diag_matrix_value, + octave_base_value::complex_diag_matrix_value, + octave_base_value::float_diag_matrix_value, + octave_base_value::float_complex_diag_matrix_value, + octave_base_value::perm_matrix_value): New virtual methods. + + * ov-base.h: Declare them. + + * ov-base-diag.h (octave_base_diag::diag_matrix_value, + octave_base_diag::complex_diag_matrix_value, + octave_base_diag::float_diag_matrix_value, + octave_base_diag::float_complex_diag_matrix_value, + octave_base_diag::perm_matrix_value): Remove declarations. + + * DLD-FUNCTIONS/inv.cc (Finv): Simplify handling diag & perm matrices. + * DLD-FUNCTIONS/pinv.cc (Fpinv): Ditto. + * DLD-FUNCTIONS/det.cc (Fdet): Ditto. + 2009-03-05 Jaroslav Hajek <highegg@gmail.com> * ls-hdf5.cc (add_hdf5_data): Handle diag & perm matrices.
--- a/src/DLD-FUNCTIONS/det.cc +++ b/src/DLD-FUNCTIONS/det.cc @@ -95,56 +95,48 @@ if (arg.is_diag_matrix ()) { - const octave_base_value& a = arg.get_rep (); if (arg.is_complex_type ()) { if (isfloat) { - CAST_CONV_ARG (const octave_float_complex_diag_matrix&); - retval(0) = v.float_complex_diag_matrix_value ().determinant ().value (); + retval(0) = arg.float_complex_diag_matrix_value ().determinant ().value (); if (nargout > 1) - retval(1) = v.float_complex_diag_matrix_value ().rcond (); + retval(1) = arg.float_complex_diag_matrix_value ().rcond (); } else { - CAST_CONV_ARG (const octave_complex_diag_matrix&); - retval(0) = v.complex_diag_matrix_value ().determinant ().value (); + retval(0) = arg.complex_diag_matrix_value ().determinant ().value (); if (nargout > 1) - retval(1) = v.complex_diag_matrix_value ().rcond (); + retval(1) = arg.complex_diag_matrix_value ().rcond (); } } else { if (isfloat) { - CAST_CONV_ARG (const octave_float_diag_matrix&); - retval(0) = v.float_diag_matrix_value ().determinant ().value (); + retval(0) = arg.float_diag_matrix_value ().determinant ().value (); if (nargout > 1) - retval(1) = v.float_diag_matrix_value ().rcond (); + retval(1) = arg.float_diag_matrix_value ().rcond (); } else { - CAST_CONV_ARG (const octave_diag_matrix&); - retval(0) = v.diag_matrix_value ().determinant ().value (); + retval(0) = arg.diag_matrix_value ().determinant ().value (); if (nargout > 1) - retval(1) = v.diag_matrix_value ().rcond (); + retval(1) = arg.diag_matrix_value ().rcond (); } } } else if (arg.is_perm_matrix ()) { - const octave_base_value& a = arg.get_rep (); if (isfloat) { - CAST_CONV_ARG (const octave_float_perm_matrix&); - retval(0) = static_cast<float> (v.perm_matrix_value ().determinant ()); + retval(0) = static_cast<float> (arg.perm_matrix_value ().determinant ()); if (nargout > 1) retval(1) = 1.0; } else { - CAST_CONV_ARG (const octave_perm_matrix&); - retval(0) = static_cast<double> (v.perm_matrix_value ().determinant ()); + retval(0) = static_cast<double> (arg.perm_matrix_value ().determinant ()); if (nargout > 1) retval(1) = 1.0f; }
--- a/src/DLD-FUNCTIONS/inv.cc +++ b/src/DLD-FUNCTIONS/inv.cc @@ -91,39 +91,34 @@ { rcond = 1.0; frcond = 1.0f; - const octave_base_value& a = arg.get_rep (); if (arg.is_complex_type ()) { if (isfloat) { - CAST_CONV_ARG (const octave_float_complex_diag_matrix&); - result = v.float_complex_diag_matrix_value ().inverse (info); + result = arg.float_complex_diag_matrix_value ().inverse (info); if (nargout > 1) - frcond = v.float_complex_diag_matrix_value ().rcond (); + frcond = arg.float_complex_diag_matrix_value ().rcond (); } else { - CAST_CONV_ARG (const octave_complex_diag_matrix&); - result = v.complex_diag_matrix_value ().inverse (info); + result = arg.complex_diag_matrix_value ().inverse (info); if (nargout > 1) - rcond = v.complex_diag_matrix_value ().rcond (); + rcond = arg.complex_diag_matrix_value ().rcond (); } } else { if (isfloat) { - CAST_CONV_ARG (const octave_float_diag_matrix&); - result = v.float_diag_matrix_value ().inverse (info); + result = arg.float_diag_matrix_value ().inverse (info); if (nargout > 1) - frcond = v.float_diag_matrix_value ().rcond (); + frcond = arg.float_diag_matrix_value ().rcond (); } else { - CAST_CONV_ARG (const octave_diag_matrix&); - result = v.diag_matrix_value ().inverse (info); + result = arg.diag_matrix_value ().inverse (info); if (nargout > 1) - rcond = v.diag_matrix_value ().rcond (); + rcond = arg.diag_matrix_value ().rcond (); } } } @@ -132,17 +127,10 @@ rcond = 1.0; frcond = 1.0f; info = 0; - const octave_base_value& a = arg.get_rep (); if (isfloat) - { - CAST_CONV_ARG (const octave_float_perm_matrix&); - result = v.perm_matrix_value ().inverse (); - } + result = octave_value (arg.perm_matrix_value ().inverse (), true); else - { - CAST_CONV_ARG (const octave_perm_matrix&); - result = v.perm_matrix_value ().inverse (); - } + result = arg.perm_matrix_value ().inverse (); } else if (isfloat) {
--- a/src/DLD-FUNCTIONS/pinv.cc +++ b/src/DLD-FUNCTIONS/pinv.cc @@ -79,47 +79,27 @@ if (nargin == 2) warning ("pinv: tol is ignored for diagonal matrices"); - const octave_base_value& a = arg.get_rep (); if (arg.is_complex_type ()) { if (isfloat) - { - CAST_CONV_ARG (const octave_float_complex_diag_matrix&); - retval = v.float_complex_diag_matrix_value ().pseudo_inverse (); - } + retval = arg.float_complex_diag_matrix_value ().pseudo_inverse (); else - { - CAST_CONV_ARG (const octave_complex_diag_matrix&); - retval = v.complex_diag_matrix_value ().pseudo_inverse (); - } + retval = arg.complex_diag_matrix_value ().pseudo_inverse (); } else { if (isfloat) - { - CAST_CONV_ARG (const octave_float_diag_matrix&); - retval = v.float_diag_matrix_value ().pseudo_inverse (); - } + retval = arg.float_diag_matrix_value ().pseudo_inverse (); else - { - CAST_CONV_ARG (const octave_diag_matrix&); - retval = v.diag_matrix_value ().pseudo_inverse (); - } + retval = arg.diag_matrix_value ().pseudo_inverse (); } } else if (arg.is_perm_matrix ()) { - const octave_base_value& a = arg.get_rep (); if (isfloat) - { - CAST_CONV_ARG (const octave_float_perm_matrix&); - retval = v.perm_matrix_value ().inverse (); - } + retval = octave_value (arg.perm_matrix_value ().inverse (), true); else - { - CAST_CONV_ARG (const octave_perm_matrix&); - retval = v.perm_matrix_value ().inverse (); - } + retval = arg.perm_matrix_value ().inverse (); } else if (isfloat) {
--- a/src/ov-base-diag.h +++ b/src/ov-base-diag.h @@ -136,14 +136,6 @@ idx_vector index_vector (void) const; - virtual DiagMatrix diag_matrix_value (bool = false) const = 0; - - virtual FloatDiagMatrix float_diag_matrix_value (bool = false) const = 0; - - virtual ComplexDiagMatrix complex_diag_matrix_value (bool = false) const = 0; - - virtual FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const = 0; - Matrix matrix_value (bool = false) const; FloatMatrix float_matrix_value (bool = false) const;
--- a/src/ov-base.cc +++ b/src/ov-base.cc @@ -608,6 +608,46 @@ return retval; } +DiagMatrix +octave_base_value::diag_matrix_value (bool) const +{ + DiagMatrix retval; + gripe_wrong_type_arg ("octave_base_value::diag_matrix_value()", type_name ()); + return retval; +} + +FloatDiagMatrix +octave_base_value::float_diag_matrix_value (bool) const +{ + FloatDiagMatrix retval; + gripe_wrong_type_arg ("octave_base_value::float_diag_matrix_value()", type_name ()); + return retval; +} + +ComplexDiagMatrix +octave_base_value::complex_diag_matrix_value (bool) const +{ + ComplexDiagMatrix retval; + gripe_wrong_type_arg ("octave_base_value::complex_diag_matrix_value()", type_name ()); + return retval; +} + +FloatComplexDiagMatrix +octave_base_value::float_complex_diag_matrix_value (bool) const +{ + FloatComplexDiagMatrix retval; + gripe_wrong_type_arg ("octave_base_value::float_complex_diag_matrix_value()", type_name ()); + return retval; +} + +PermMatrix +octave_base_value::perm_matrix_value (void) const +{ + PermMatrix retval; + gripe_wrong_type_arg ("octave_base_value::perm_matrix_value()", type_name ()); + return retval; +} + octave_int8 octave_base_value::int8_scalar_value (void) const {
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -396,6 +396,16 @@ virtual SparseBoolMatrix sparse_bool_matrix_value (bool = false) const; + virtual DiagMatrix diag_matrix_value (bool = false) const; + + virtual FloatDiagMatrix float_diag_matrix_value (bool = false) const; + + virtual ComplexDiagMatrix complex_diag_matrix_value (bool = false) const; + + virtual FloatComplexDiagMatrix float_complex_diag_matrix_value (bool = false) const; + + virtual PermMatrix perm_matrix_value (void) const; + virtual octave_int8 int8_scalar_value (void) const; virtual octave_int16 int16_scalar_value (void) const;
--- a/src/ov.h +++ b/src/ov.h @@ -740,6 +740,21 @@ SparseBoolMatrix sparse_bool_matrix_value (bool frc_str_conv = false) const { return rep->sparse_bool_matrix_value (frc_str_conv); } + DiagMatrix diag_matrix_value (bool force = false) const + { return rep->diag_matrix_value (force); } + + FloatDiagMatrix float_diag_matrix_value (bool force = false) const + { return rep->float_diag_matrix_value (force); } + + ComplexDiagMatrix complex_diag_matrix_value (bool force = false) const + { return rep->complex_diag_matrix_value (force); } + + FloatComplexDiagMatrix float_complex_diag_matrix_value (bool force = false) const + { return rep->float_complex_diag_matrix_value (force); } + + PermMatrix perm_matrix_value (void) const + { return rep->perm_matrix_value (); } + octave_int8 int8_scalar_value (void) const { return rep->int8_scalar_value (); }