# HG changeset patch # User Jaroslav Hajek # Date 1236846277 -3600 # Node ID 93f18f166aba08a1d0ced6a41f2e57f103ead679 # Parent 089abf117499d379ac28f8eb8a2ec19b096893ea remove float perm matrices diff -r 089abf117499 -r 93f18f166aba src/ChangeLog --- a/src/ChangeLog Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ChangeLog Thu Mar 12 09:24:37 2009 +0100 @@ -1,3 +1,30 @@ +2009-03-12 Jaroslav Hajek + + * 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 * xpow.cc (xpow (const PermMatrix&, double), xpow (const PermMatrix&, diff -r 089abf117499 -r 93f18f166aba src/DLD-FUNCTIONS/det.cc --- a/src/DLD-FUNCTIONS/det.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/DLD-FUNCTIONS/det.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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 (arg.perm_matrix_value ().determinant ()); - if (nargout > 1) - retval(1) = 1.0; - } - else - { - retval(0) = static_cast (arg.perm_matrix_value ().determinant ()); - if (nargout > 1) - retval(1) = 1.0f; - } + retval(0) = static_cast (arg.perm_matrix_value ().determinant ()); + if (nargout > 1) + retval(1) = 1.0; } else if (arg.is_single_type ()) { diff -r 089abf117499 -r 93f18f166aba src/DLD-FUNCTIONS/inv.cc --- a/src/DLD-FUNCTIONS/inv.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/DLD-FUNCTIONS/inv.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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) { diff -r 089abf117499 -r 93f18f166aba src/DLD-FUNCTIONS/pinv.cc --- a/src/DLD-FUNCTIONS/pinv.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/DLD-FUNCTIONS/pinv.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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) { diff -r 089abf117499 -r 93f18f166aba src/Makefile.in --- a/src/Makefile.in Wed Mar 11 14:10:36 2009 +0100 +++ b/src/Makefile.in Thu Mar 12 09:24:37 2009 +0100 @@ -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) diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fcm-fpm.cc --- a/src/OPERATORS/op-fcm-fpm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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 -. - -*/ - -#define MINCLUDE "ov-flt-cx-mat.h" - -#define LMATRIX float_complex_matrix -#define RMATRIX float_perm_matrix - -#define LSHORT fcm -#define RSHORT fpm - -#define RIGHT - -#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fcm-pm.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/OPERATORS/op-fcm-pm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -0,0 +1,33 @@ +/* + +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 +. + +*/ + +#define MINCLUDE "ov-flt-cx-mat.h" + +#define LMATRIX float_complex_matrix +#define RMATRIX perm_matrix + +#define LSHORT fcm +#define RSHORT pm + +#define RIGHT + +#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fm-fpm.cc --- a/src/OPERATORS/op-fm-fpm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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 -. - -*/ - -#define MINCLUDE "ov-flt-re-mat.h" - -#define LMATRIX float_matrix -#define RMATRIX float_perm_matrix - -#define LSHORT fm -#define RSHORT fpm - -#define RIGHT - -#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fm-pm.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/OPERATORS/op-fm-pm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -0,0 +1,33 @@ +/* + +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 +. + +*/ + +#define MINCLUDE "ov-flt-re-mat.h" + +#define LMATRIX float_matrix +#define RMATRIX perm_matrix + +#define LSHORT fm +#define RSHORT pm + +#define RIGHT + +#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fpm-fcm.cc --- a/src/OPERATORS/op-fpm-fcm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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 -. - -*/ - -#define MINCLUDE "ov-flt-cx-mat.h" - -#define LMATRIX float_perm_matrix -#define RMATRIX float_complex_matrix - -#define LSHORT fpm -#define RSHORT fcm - -#define LEFT - -#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fpm-fm.cc --- a/src/OPERATORS/op-fpm-fm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +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 -. - -*/ - -#define MINCLUDE "ov-flt-re-mat.h" - -#define LMATRIX float_perm_matrix -#define RMATRIX float_matrix - -#define LSHORT fpm -#define RSHORT fm - -#define LEFT - -#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-fpm-fpm.cc --- a/src/OPERATORS/op-fpm-fpm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#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); -} - diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-pm-fcm.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/OPERATORS/op-pm-fcm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -0,0 +1,33 @@ +/* + +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 +. + +*/ + +#define MINCLUDE "ov-flt-cx-mat.h" + +#define LMATRIX perm_matrix +#define RMATRIX float_complex_matrix + +#define LSHORT pm +#define RSHORT fcm + +#define LEFT + +#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-pm-fm.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/OPERATORS/op-pm-fm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -0,0 +1,33 @@ +/* + +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 +. + +*/ + +#define MINCLUDE "ov-flt-re-mat.h" + +#define LMATRIX perm_matrix +#define RMATRIX float_matrix + +#define LSHORT pm +#define RSHORT fm + +#define LEFT + +#include "op-pm-template.cc" diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-pm-pm.cc --- a/src/OPERATORS/op-pm-pm.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/OPERATORS/op-pm-pm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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); } diff -r 089abf117499 -r 93f18f166aba src/OPERATORS/op-pm-template.cc --- a/src/OPERATORS/op-pm-template.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/OPERATORS/op-pm-template.cc Thu Mar 12 09:24:37 2009 +0100 @@ -25,7 +25,6 @@ #endif #include "ov-perm.h" -#include "ov-flt-perm.h" #include MINCLUDE #include "ops.h" diff -r 089abf117499 -r 93f18f166aba src/ov-base-diag.cc --- a/src/ov-base-diag.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-base-diag.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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; } diff -r 089abf117499 -r 93f18f166aba src/ov-flt-perm.cc --- a/src/ov-flt-perm.cc Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#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; -} - diff -r 089abf117499 -r 93f18f166aba src/ov-flt-perm.h --- a/src/ov-flt-perm.h Wed Mar 11 14:10:36 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -. - -*/ - -#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 diff -r 089abf117499 -r 93f18f166aba src/ov-flt-re-mat.cc --- a/src/ov-flt-re-mat.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-flt-re-mat.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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 ()) { diff -r 089abf117499 -r 93f18f166aba src/ov-perm.cc --- a/src/ov-perm.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-perm.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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) { diff -r 089abf117499 -r 93f18f166aba src/ov-perm.h --- a/src/ov-perm.h Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-perm.h Thu Mar 12 09:24:37 2009 +0100 @@ -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 (); } diff -r 089abf117499 -r 93f18f166aba src/ov-re-diag.cc --- a/src/ov-re-diag.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-re-diag.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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::do_index_op (idx, resize_ok); + + return retval; +} + DiagMatrix octave_diag_matrix::diag_matrix_value (bool) const { diff -r 089abf117499 -r 93f18f166aba src/ov-re-diag.h --- a/src/ov-re-diag.h Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov-re-diag.h Thu Mar 12 09:24:37 2009 +0100 @@ -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; } diff -r 089abf117499 -r 93f18f166aba src/ov.cc --- a/src/ov.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov.cc Thu Mar 12 09:24:37 2009 +0100 @@ -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 (); diff -r 089abf117499 -r 93f18f166aba src/ov.h --- a/src/ov.h Wed Mar 11 14:10:36 2009 +0100 +++ b/src/ov.h Thu Mar 12 09:24:37 2009 +0100 @@ -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); diff -r 089abf117499 -r 93f18f166aba src/xpow.cc --- a/src/xpow.cc Wed Mar 11 14:10:36 2009 +0100 +++ b/src/xpow.cc Thu Mar 12 09:24:37 2009 +0100 @@ -1589,18 +1589,6 @@ return retval; } -// -*- 5p -*- -octave_value -xpow (const PermMatrix& a, float b) -{ - octave_value retval; - int btmp = static_cast (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) diff -r 089abf117499 -r 93f18f166aba src/xpow.h --- a/src/xpow.h Wed Mar 11 14:10:36 2009 +0100 +++ b/src/xpow.h Thu Mar 12 09:24:37 2009 +0100 @@ -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);