Mercurial > hg > octave-terminal
changeset 8960:93f18f166aba
remove float perm matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 12 Mar 2009 09:24:37 +0100 |
parents | 089abf117499 |
children | 6b87f2f34fdd |
files | src/ChangeLog src/DLD-FUNCTIONS/det.cc src/DLD-FUNCTIONS/inv.cc src/DLD-FUNCTIONS/pinv.cc src/Makefile.in src/OPERATORS/op-fcm-fpm.cc src/OPERATORS/op-fcm-pm.cc src/OPERATORS/op-fm-fpm.cc src/OPERATORS/op-fm-pm.cc src/OPERATORS/op-fpm-fcm.cc src/OPERATORS/op-fpm-fm.cc src/OPERATORS/op-fpm-fpm.cc src/OPERATORS/op-pm-fcm.cc src/OPERATORS/op-pm-fm.cc src/OPERATORS/op-pm-pm.cc src/OPERATORS/op-pm-template.cc src/ov-base-diag.cc src/ov-flt-perm.cc src/ov-flt-perm.h src/ov-flt-re-mat.cc src/ov-perm.cc src/ov-perm.h src/ov-re-diag.cc src/ov-re-diag.h src/ov.cc src/ov.h src/xpow.cc src/xpow.h |
diffstat | 24 files changed, 107 insertions(+), 383 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,30 @@ +2009-03-12 Jaroslav Hajek <highegg@gmail.com> + + * ov-flt-perm.h, ov-flt-perm.cc: Remove sources. + * ov.h, ov.cc (octave_value::octave_value (const PermMatrix&)): Remove + use "single" argument. + * ov.cc (install_types): Update. + * xpow.cc, xpow.h (xpow (PermMatrix, float)): Remove. + * ov-base-diag.cc (octave_base_diag::do_index_op): Remove permutation + creating block. + * ov-re-diag.cc (octave_diag_matrix::do_index_op): Move it here. + * ov-re-diag.h (octave_diag_matrix::do_index_op): New decl. + + * DLD-FUNCTIONS/det.cc (Fdet): Update. + * DLD-FUNCTIONS/inv.cc (Finv): Update. + * DLD-FUNCTIONS/pinv.cc (Fpinv): Update. + + * OPERATORS/op-fcm-pm.cc <-- OPERATORS/op-fcm-fpm.cc + * OPERATORS/op-fcm-pm.cc: Update. + * OPERATORS/op-fm-pm.cc <-- OPERATORS/op-fm-fpm.cc + * OPERATORS/op-fm-pm.cc: Update. + * OPERATORS/op-pm-fcm.cc <-- OPERATORS/op-fpm-fcm.cc + * OPERATORS/op-pm-fcm.cc: Update. + * OPERATORS/op-pm-fm.cc <-- OPERATORS/op-fpm-fm.cc + * OPERATORS/op-pm-fm.cc: Update. + * OPERATORS/op-pm-pm.cc: Update. + * OPERATORS/op-pm-template.cc: Update. + 2009-03-11 Jaroslav Hajek <highegg@gmail.com> * xpow.cc (xpow (const PermMatrix&, double), xpow (const PermMatrix&,
--- a/src/DLD-FUNCTIONS/det.cc +++ b/src/DLD-FUNCTIONS/det.cc @@ -43,7 +43,6 @@ #include "ov-flt-re-diag.h" #include "ov-flt-cx-diag.h" #include "ov-perm.h" -#include "ov-flt-perm.h" #define MAYBE_CAST(VAR, CLASS) \ const CLASS *VAR = arg.type_id () == CLASS::static_type_id () ? \ @@ -128,18 +127,9 @@ } else if (arg.is_perm_matrix ()) { - if (isfloat) - { - retval(0) = static_cast<float> (arg.perm_matrix_value ().determinant ()); - if (nargout > 1) - retval(1) = 1.0; - } - else - { - retval(0) = static_cast<double> (arg.perm_matrix_value ().determinant ()); - if (nargout > 1) - retval(1) = 1.0f; - } + retval(0) = static_cast<double> (arg.perm_matrix_value ().determinant ()); + if (nargout > 1) + retval(1) = 1.0; } else if (arg.is_single_type ()) {
--- a/src/DLD-FUNCTIONS/inv.cc +++ b/src/DLD-FUNCTIONS/inv.cc @@ -35,7 +35,6 @@ #include "ov-flt-re-diag.h" #include "ov-flt-cx-diag.h" #include "ov-perm.h" -#include "ov-flt-perm.h" #include "utils.h" DEFUN_DLD (inv, args, nargout, @@ -125,12 +124,8 @@ else if (arg.is_perm_matrix ()) { rcond = 1.0; - frcond = 1.0f; info = 0; - if (isfloat) - result = octave_value (arg.perm_matrix_value ().inverse (), true); - else - result = arg.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 @@ -36,7 +36,6 @@ #include "ov-flt-re-diag.h" #include "ov-flt-cx-diag.h" #include "ov-perm.h" -#include "ov-flt-perm.h" DEFUN_DLD (pinv, args, , "-*- texinfo -*-\n\ @@ -97,10 +96,7 @@ } else if (arg.is_perm_matrix ()) { - if (isfloat) - retval = octave_value (arg.perm_matrix_value ().inverse (), true); - else - retval = arg.perm_matrix_value ().inverse (); + retval = arg.perm_matrix_value ().inverse (); } else if (isfloat) {
--- a/src/Makefile.in +++ b/src/Makefile.in @@ -102,8 +102,8 @@ ov-struct.h ov-scalar.h ov-range.h ov-complex.h \ ov-colon.h ov-base.h ov-base-mat.h ov-base-scalar.h \ ov-str-mat.h ov-bool-mat.h ov-null-mat.h ov-bool.h \ - ov-base-diag.h ov-re-diag.h ov-flt-re-diag.h ov-cx-diag.h ov-flt-cx-diag.h \ - ov-perm.h ov-flt-perm.h \ + ov-base-diag.h ov-re-diag.h ov-flt-re-diag.h ov-cx-diag.h \ + ov-flt-cx-diag.h ov-perm.h \ ov-cell.h ov.h ov-fcn.h ov-builtin.h ov-dld-fcn.h \ ov-mex-fcn.h ov-usr-fcn.h ov-fcn-handle.h \ ov-fcn-inline.h ov-class.h ov-typeinfo.h ov-type-conv.h \ @@ -173,8 +173,8 @@ op-fdm-fcdm.cc op-fdm-fcm.cc op-fdm-fcs.cc op-fdm-fdm.cc \ op-fdm-fm.cc op-fdm-fs.cc op-fm-fcdm.cc op-fm-fdm.cc -PERM_OP_XSRC := op-cm-pm.cc op-fcm-fpm.cc op-fm-fpm.cc op-fpm-fcm.cc \ - op-fpm-fm.cc op-fpm-fpm.cc op-m-pm.cc op-pm-cm.cc op-pm-m.cc op-pm-pm.cc +PERM_OP_XSRC := op-cm-pm.cc op-fcm-pm.cc op-fm-pm.cc op-pm-fcm.cc \ + op-pm-fm.cc op-m-pm.cc op-pm-cm.cc op-pm-m.cc op-pm-pm.cc OP_XSRC := op-b-b.cc op-b-bm.cc op-bm-b.cc op-bm-bm.cc op-cell.cc \ op-chm.cc op-class.cc op-list.cc op-range.cc op-str-m.cc \ @@ -204,7 +204,7 @@ ov-class.cc ov-typeinfo.cc \ ov-flt-re-mat.cc ov-flt-cx-mat.cc ov-float.cc ov-flt-complex.cc \ ov-re-diag.cc ov-flt-re-diag.cc ov-cx-diag.cc ov-flt-cx-diag.cc \ - ov-perm.cc ov-flt-perm.cc \ + ov-perm.cc \ $(OV_INTTYPE_SRC) \ $(OV_SPARSE_SRC)
rename from src/OPERATORS/op-fcm-fpm.cc rename to src/OPERATORS/op-fcm-pm.cc --- a/src/OPERATORS/op-fcm-fpm.cc +++ b/src/OPERATORS/op-fcm-pm.cc @@ -23,10 +23,10 @@ #define MINCLUDE "ov-flt-cx-mat.h" #define LMATRIX float_complex_matrix -#define RMATRIX float_perm_matrix +#define RMATRIX perm_matrix #define LSHORT fcm -#define RSHORT fpm +#define RSHORT pm #define RIGHT
rename from src/OPERATORS/op-fm-fpm.cc rename to src/OPERATORS/op-fm-pm.cc --- a/src/OPERATORS/op-fm-fpm.cc +++ b/src/OPERATORS/op-fm-pm.cc @@ -23,10 +23,10 @@ #define MINCLUDE "ov-flt-re-mat.h" #define LMATRIX float_matrix -#define RMATRIX float_perm_matrix +#define RMATRIX perm_matrix #define LSHORT fm -#define RSHORT fpm +#define RSHORT pm #define RIGHT
deleted file mode 100644 --- a/src/OPERATORS/op-fpm-fpm.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - -Copyright (C) 2008, 2009 Jaroslav Hajek - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gripes.h" -#include "oct-obj.h" -#include "ov.h" -#include "ov-perm.h" -#include "ov-flt-perm.h" -#include "ov-flt-re-mat.h" -#include "ov-float.h" -#include "ov-typeinfo.h" -#include "ops.h" -#include "xpow.h" - -DEFUNOP (transpose, float_perm_matrix) -{ - CAST_UNOP_ARG (const octave_float_perm_matrix&); - return octave_value (v.perm_matrix_value().transpose (), true); -} - -DEFBINOP (mul, float_perm_matrix, float_perm_matrix) -{ - CAST_BINOP_ARGS (const octave_float_perm_matrix&, const octave_float_perm_matrix&); - - return octave_value (v1.perm_matrix_value () * v2.perm_matrix_value (), true); -} - -DEFBINOP (div, float_perm_matrix, float_perm_matrix) -{ - CAST_BINOP_ARGS (const octave_float_perm_matrix&, const octave_float_perm_matrix&); - - return octave_value (v1.perm_matrix_value () * v2.perm_matrix_value ().inverse (), false); -} - -DEFBINOP (ldiv, float_perm_matrix, float_perm_matrix) -{ - CAST_BINOP_ARGS (const octave_float_perm_matrix&, const octave_float_perm_matrix&); - - return octave_value (v1.perm_matrix_value ().inverse () * v2.perm_matrix_value (), false); -} - -DEFBINOP (pow, float_perm_matrix, float_scalar) -{ - CAST_BINOP_ARGS (const octave_float_perm_matrix&, const octave_float_scalar&); - - return xpow (v1.perm_matrix_value (), v2.float_scalar_value ()); -} - -CONVDECL (float_perm_matrix_to_float_matrix) -{ - CAST_CONV_ARG (const octave_float_perm_matrix&); - - return new octave_float_matrix (v.float_matrix_value ()); -} - -CONVDECL (float_perm_matrix_to_perm_matrix) -{ - CAST_CONV_ARG (const octave_float_perm_matrix&); - - return new octave_perm_matrix (v.perm_matrix_value ()); -} - -void -install_fpm_fpm_ops (void) -{ - INSTALL_UNOP (op_transpose, octave_float_perm_matrix, transpose); - INSTALL_UNOP (op_hermitian, octave_float_perm_matrix, transpose); - - INSTALL_BINOP (op_mul, octave_float_perm_matrix, octave_float_perm_matrix, mul); - INSTALL_BINOP (op_div, octave_float_perm_matrix, octave_float_perm_matrix, div); - INSTALL_BINOP (op_ldiv, octave_float_perm_matrix, octave_float_perm_matrix, ldiv); - INSTALL_BINOP (op_pow, octave_float_perm_matrix, octave_float_scalar, pow); - - INSTALL_CONVOP (octave_float_perm_matrix, octave_float_matrix, float_perm_matrix_to_float_matrix); - INSTALL_CONVOP (octave_float_perm_matrix, octave_perm_matrix, float_perm_matrix_to_perm_matrix); - INSTALL_ASSIGNCONV (octave_float_perm_matrix, octave_float_matrix, octave_float_matrix); - INSTALL_WIDENOP (octave_float_perm_matrix, octave_float_matrix, float_perm_matrix_to_float_matrix); -} -
rename from src/OPERATORS/op-fpm-fcm.cc rename to src/OPERATORS/op-pm-fcm.cc --- a/src/OPERATORS/op-fpm-fcm.cc +++ b/src/OPERATORS/op-pm-fcm.cc @@ -22,10 +22,10 @@ #define MINCLUDE "ov-flt-cx-mat.h" -#define LMATRIX float_perm_matrix +#define LMATRIX perm_matrix #define RMATRIX float_complex_matrix -#define LSHORT fpm +#define LSHORT pm #define RSHORT fcm #define LEFT
rename from src/OPERATORS/op-fpm-fm.cc rename to src/OPERATORS/op-pm-fm.cc --- a/src/OPERATORS/op-fpm-fm.cc +++ b/src/OPERATORS/op-pm-fm.cc @@ -22,10 +22,10 @@ #define MINCLUDE "ov-flt-re-mat.h" -#define LMATRIX float_perm_matrix +#define LMATRIX perm_matrix #define RMATRIX float_matrix -#define LSHORT fpm +#define LSHORT pm #define RSHORT fm #define LEFT
--- a/src/OPERATORS/op-pm-pm.cc +++ b/src/OPERATORS/op-pm-pm.cc @@ -28,7 +28,6 @@ #include "oct-obj.h" #include "ov.h" #include "ov-perm.h" -#include "ov-flt-perm.h" #include "ov-re-mat.h" #include "ov-scalar.h" #include "ov-typeinfo.h" @@ -71,13 +70,6 @@ return new octave_matrix (v.matrix_value ()); } -CONVDECL (perm_matrix_to_float_perm_matrix) -{ - CAST_CONV_ARG (const octave_perm_matrix&); - - return new octave_float_perm_matrix (v.perm_matrix_value ()); -} - void install_pm_pm_ops (void) { @@ -90,7 +82,6 @@ INSTALL_BINOP (op_pow, octave_perm_matrix, octave_scalar, pow); INSTALL_CONVOP (octave_perm_matrix, octave_matrix, perm_matrix_to_matrix); - INSTALL_CONVOP (octave_perm_matrix, octave_float_perm_matrix, perm_matrix_to_float_perm_matrix); INSTALL_ASSIGNCONV (octave_perm_matrix, octave_matrix, octave_matrix); INSTALL_WIDENOP (octave_perm_matrix, octave_matrix, perm_matrix_to_matrix); }
--- a/src/OPERATORS/op-pm-template.cc +++ b/src/OPERATORS/op-pm-template.cc @@ -25,7 +25,6 @@ #endif #include "ov-perm.h" -#include "ov-flt-perm.h" #include MINCLUDE #include "ops.h"
--- a/src/ov-base-diag.cc +++ b/src/ov-base-diag.cc @@ -73,57 +73,18 @@ { octave_value retval; typedef typename DMT::element_type el_type; - el_type one = 1; - - octave_idx_type nidx = idx.length (); - idx_vector idx0, idx1; - if (nidx == 2) - { - idx0 = idx(0).index_vector (); - idx1 = idx(1).index_vector (); - } - - // This hack is to allow constructing permutation matrices using - // eye(n)(p,:), eye(n)(:,q) && eye(n)(p,q) where p & q are permutation - // vectors. - // FIXME: This check is probably unnecessary for complex matrices. - if (! error_state && nidx == 2 && matrix.is_multiple_of_identity (one)) - { - - bool left = idx0.is_permutation (matrix.rows ()); - bool right = idx1.is_permutation (matrix.cols ()); - if (left && right) - { - if (idx0.is_colon ()) left = false; - if (idx1.is_colon ()) right = false; - if (left && right) - retval = octave_value (PermMatrix (idx0, false) * PermMatrix (idx1, true), - is_single_type ()); - else if (left) - retval = octave_value (PermMatrix (idx0, false), - is_single_type ()); - else if (right) - retval = octave_value (PermMatrix (idx1, true), - is_single_type ()); - else - { - retval = this; - this->count++; - } - } - } + if (idx.length () == 2 && ! resize_ok) + { + idx_vector idx0 = idx(0).index_vector (); + idx_vector idx1 = idx(1).index_vector (); - // if error_state is set, we've already griped. - if (! error_state && ! retval.is_defined ()) - { - if (nidx == 2 && ! resize_ok && - idx0.is_scalar () && idx1.is_scalar ()) + if (idx0.is_scalar () && idx1.is_scalar ()) { // FIXME: the proxy mechanism of DiagArray2 causes problems here. retval = el_type (matrix.checkelem (idx0(0), idx1(0))); } - else if (nidx == 2 && ! resize_ok) + else { octave_idx_type m = idx0.length (matrix.rows ()); octave_idx_type n = idx1.length (matrix.columns ()); @@ -137,9 +98,9 @@ else retval = to_dense ().do_index_op (idx, resize_ok); } - else - retval = to_dense ().do_index_op (idx, resize_ok); } + else + retval = to_dense ().do_index_op (idx, resize_ok); return retval; }
deleted file mode 100644 --- a/src/ov-flt-perm.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - -Copyright (C) 2008 Jaroslav Hajek - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "ov-flt-perm.h" -#include "ov-flt-re-mat.h" -#include "ov-float.h" -#include "ops.h" - -DEFINE_OCTAVE_ALLOCATOR (octave_float_perm_matrix); - -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_float_perm_matrix, - "float permutation matrix", "single"); - -static octave_base_value * -default_float_numeric_conversion_function (const octave_base_value& a) -{ - CAST_CONV_ARG (const octave_float_perm_matrix&); - - return new octave_float_matrix (v.float_matrix_value ()); -} - -octave_base_value::type_conv_info -octave_float_perm_matrix::numeric_conversion_function (void) const -{ - return octave_base_value::type_conv_info (default_float_numeric_conversion_function, - octave_float_matrix::static_type_id ()); -} - -octave_base_value::type_conv_info -octave_float_perm_matrix::numeric_demotion_function (void) const -{ - return octave_base_value::type_conv_info (0); -} - -octave_base_value * -octave_float_perm_matrix::try_narrowing_conversion (void) -{ - octave_base_value *retval = 0; - - if (matrix.nelem () == 1) - retval = new octave_float_scalar (matrix (0, 0)); - - return retval; -} - -octave_value -octave_float_perm_matrix::to_dense (void) const -{ - if (! dense_cache.is_defined ()) - dense_cache = FloatMatrix (matrix); - - return dense_cache; -} -
deleted file mode 100644 --- a/src/ov-flt-perm.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - -Copyright (C) 2008 Jaroslav Hajek - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if !defined (octave_float_perm_matrix_h) -#define octave_float_perm_matrix_h 1 - -#include "ov-perm.h" -#include "ov-perm.h" - -class -OCTINTERP_API -octave_float_perm_matrix : public octave_perm_matrix -{ -public: - octave_float_perm_matrix (void) : octave_perm_matrix () { } - - octave_float_perm_matrix (const PermMatrix& p) : octave_perm_matrix (p) { } - - octave_base_value *clone (void) const { return new octave_float_perm_matrix (*this); } - octave_base_value *empty_clone (void) const { return new octave_float_perm_matrix (); } - - bool is_double_type (void) const { return false; } - - bool is_single_type (void) const { return true; } - - type_conv_info numeric_conversion_function (void) const; - - type_conv_info numeric_demotion_function (void) const; - - octave_base_value *try_narrowing_conversion (void); - -protected: - - virtual octave_value to_dense (void) const; - -private: - - DECLARE_OCTAVE_ALLOCATOR - - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA -}; - -#endif
--- a/src/ov-flt-re-mat.cc +++ b/src/ov-flt-re-mat.cc @@ -58,7 +58,6 @@ #include "ov-re-sparse.h" #include "ov-flt-re-diag.h" #include "ov-flt-cx-diag.h" -#include "ov-flt-perm.h" #include "ov-type-conv.h" #include "pr-output.h" #include "variables.h" @@ -815,11 +814,7 @@ if (args.length () == 1) { - if (args(0).is_perm_matrix ()) - { - OCTAVE_TYPE_CONV_BODY3 (single, octave_float_perm_matrix, octave_float_scalar); - } - else if (args(0).is_diag_matrix ()) + if (args(0).is_diag_matrix ()) { if (args(0).is_complex_type ()) {
--- a/src/ov-perm.cc +++ b/src/ov-perm.cc @@ -27,7 +27,6 @@ #include "byte-swap.h" #include "ov-perm.h" -#include "ov-flt-perm.h" #include "ov-re-mat.h" #include "ov-scalar.h" #include "error.h" @@ -98,7 +97,7 @@ p = PermMatrix (idx0, false) * p; if (right) p = p * PermMatrix (idx1, true); - retval = octave_value (p, is_single_type ()); + retval = p; } else { @@ -479,21 +478,6 @@ octave_matrix::static_type_id ()); } -static octave_base_value * -default_numeric_demotion_function (const octave_base_value& a) -{ - CAST_CONV_ARG (const octave_perm_matrix&); - - return new octave_float_perm_matrix (v.perm_matrix_value ()); -} - -octave_base_value::type_conv_info -octave_perm_matrix::numeric_demotion_function (void) const -{ - return octave_base_value::type_conv_info (default_numeric_demotion_function, - octave_float_perm_matrix::static_type_id ()); -} - octave_base_value * octave_perm_matrix::try_narrowing_conversion (void) {
--- a/src/ov-perm.h +++ b/src/ov-perm.h @@ -44,8 +44,6 @@ type_conv_info numeric_conversion_function (void) const; - type_conv_info numeric_demotion_function (void) const; - octave_base_value *try_narrowing_conversion (void); size_t byte_size (void) const { return matrix.byte_size (); }
--- a/src/ov-re-diag.cc +++ b/src/ov-re-diag.cc @@ -81,6 +81,51 @@ return retval; } +octave_value +octave_diag_matrix::do_index_op (const octave_value_list& idx, + bool resize_ok) +{ + octave_value retval; + + // This hack is to allow constructing permutation matrices using + // eye(n)(p,:), eye(n)(:,q) && eye(n)(p,q) where p & q are permutation + // vectors. + if (! resize_ok && idx.length () == 2 && matrix.is_multiple_of_identity (1)) + { + idx_vector idx0 = idx(0).index_vector (); + idx_vector idx1 = idx(1).index_vector (); + + if (! error_state) + { + bool left = idx0.is_permutation (matrix.rows ()); + bool right = idx1.is_permutation (matrix.cols ()); + + if (left && right) + { + if (idx0.is_colon ()) left = false; + if (idx1.is_colon ()) right = false; + if (left && right) + retval = PermMatrix (idx0, false) * PermMatrix (idx1, true); + else if (left) + retval = PermMatrix (idx0, false); + else if (right) + retval = PermMatrix (idx1, true); + else + { + retval = this; + this->count++; + } + } + } + } + + // if error_state is set, we've already griped. + if (! error_state && retval.is_undefined ()) + retval = octave_base_diag<DiagMatrix, Matrix>::do_index_op (idx, resize_ok); + + return retval; +} + DiagMatrix octave_diag_matrix::diag_matrix_value (bool) const {
--- a/src/ov-re-diag.h +++ b/src/ov-re-diag.h @@ -57,6 +57,9 @@ octave_base_value *try_narrowing_conversion (void); + octave_value do_index_op (const octave_value_list& idx, + bool resize_ok = false); + bool is_real_matrix (void) const { return true; } bool is_real_type (void) const { return true; }
--- a/src/ov.cc +++ b/src/ov.cc @@ -43,7 +43,6 @@ #include "ov-re-diag.h" #include "ov-flt-re-diag.h" #include "ov-perm.h" -#include "ov-flt-perm.h" #include "ov-bool-sparse.h" #include "ov-cx-sparse.h" #include "ov-re-sparse.h" @@ -693,13 +692,10 @@ maybe_mutate (); } -octave_value::octave_value (const PermMatrix& p, bool single) - : rep () +octave_value::octave_value (const PermMatrix& p) + : rep (new octave_perm_matrix (p)) { - if (single) - rep = new octave_float_perm_matrix (p); - else - rep = new octave_perm_matrix (p); + maybe_mutate (); } octave_value::octave_value (bool b) @@ -2481,7 +2477,6 @@ octave_float_complex_matrix::register_type (); octave_float_complex_diag_matrix::register_type (); octave_perm_matrix::register_type (); - octave_float_perm_matrix::register_type (); octave_null_matrix::register_type (); octave_null_str::register_type (); octave_null_sq_str::register_type ();
--- a/src/ov.h +++ b/src/ov.h @@ -204,7 +204,7 @@ octave_value (const FloatComplexRowVector& v); octave_value (const ComplexColumnVector& v); octave_value (const FloatComplexColumnVector& v); - octave_value (const PermMatrix& p, bool single = false); + octave_value (const PermMatrix& p); octave_value (bool b); octave_value (const boolMatrix& bm, const MatrixType& t = MatrixType()); octave_value (const boolNDArray& bnda);
--- a/src/xpow.cc +++ b/src/xpow.cc @@ -1589,18 +1589,6 @@ return retval; } -// -*- 5p -*- -octave_value -xpow (const PermMatrix& a, float b) -{ - octave_value retval; - int btmp = static_cast<int> (b); - if (btmp == b) - return octave_value (a.power (btmp), true); - else - return xpow (FloatMatrix (a), b); -} - // -*- 6 -*- octave_value xpow (const FloatMatrix& a, const FloatComplex& b)
--- a/src/xpow.h +++ b/src/xpow.h @@ -109,8 +109,6 @@ extern octave_value xpow (const FloatDiagMatrix& a, float b); extern octave_value xpow (const FloatDiagMatrix& a, const FloatComplex& b); -extern octave_value xpow (const PermMatrix& a, float b); - extern octave_value xpow (const FloatComplex& a, float b); extern octave_value xpow (const FloatComplex& a, const FloatMatrix& b); extern octave_value xpow (const FloatComplex& a, const FloatComplex& b);