# HG changeset patch # User Jaroslav Hajek # Date 1231765408 -3600 # Node ID d17874a6f161f8fba1e1121d144622ff952e84d6 # Parent d254a21e0120367992e8357a0cf433a6c3f8af72 improve indexing of diagonal & permutation matrices diff -r d254a21e0120 -r d17874a6f161 src/ChangeLog --- a/src/ChangeLog Mon Jan 12 13:06:06 2009 +0100 +++ b/src/ChangeLog Mon Jan 12 14:03:28 2009 +0100 @@ -1,3 +1,12 @@ +2009-01-12 Jaroslav Hajek + + * ov-perm.cc (octave_perm_matrix::do_index_op): Return shallow copy + when indexed by (:,:). + * ov-base-mat.cc (octave_base_diag::do_index_op): Return shallow copy + when indexed by (:,:). Optimize indexing equivalent to resizing. + * data.cc: Fix tests. + * mappers.cc: Fix tests. + 2009-01-12 Jaroslav Hajek * ov-base-diag.h, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.h, @@ -6,7 +15,6 @@ subclasses. * data.cc (Ffull): New DEFUN. * DLD-FUNCTIONS/sparse.cc (Ffull): move to data.cc. - 2009-01-11 Jaroslav Hajek * ov.h (octave_value::is_copy_of): New method. diff -r d254a21e0120 -r d17874a6f161 src/data.cc --- a/src/data.cc Mon Jan 12 13:06:06 2009 +0100 +++ b/src/data.cc Mon Jan 12 14:03:28 2009 +0100 @@ -1639,7 +1639,7 @@ /* -%!assert(diag ([1; 2; 3])(:,:), [1, 0, 0; 0, 2, 0; 0, 0, 3]); +%!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]); %!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]); %!assert(diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]); %!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]); @@ -1649,7 +1649,7 @@ %!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]); %!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]); -%!assert(diag (single([1; 2; 3]))(:,:), single([1, 0, 0; 0, 2, 0; 0, 0, 3])); +%!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3])); %!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); %!assert(diag (single([1; 2; 3]), 2), single([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])); %!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); @@ -4217,11 +4217,11 @@ /* -%!assert (eye(3)(:,:), [1, 0, 0; 0, 1, 0; 0, 0, 1]); -%!assert (eye(2, 3)(:,:), [1, 0, 0; 0, 1, 0]); - -%!assert (eye(3,'single')(:,:), single([1, 0, 0; 0, 1, 0; 0, 0, 1])); -%!assert (eye(2, 3,'single')(:,:), single([1, 0, 0; 0, 1, 0])); +%!assert (full (eye(3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]); +%!assert (full (eye(2, 3)), [1, 0, 0; 0, 1, 0]); + +%!assert (full (eye(3,'single')), single([1, 0, 0; 0, 1, 0; 0, 0, 1])); +%!assert (full (eye(2, 3,'single')), single([1, 0, 0; 0, 1, 0])); %!assert (eye(3,'int8'), int8([1, 0, 0; 0, 1, 0; 0, 0, 1])); %!assert (eye(2, 3,'int8'), int8([1, 0, 0; 0, 1, 0])); diff -r d254a21e0120 -r d17874a6f161 src/mappers.cc --- a/src/mappers.cc Mon Jan 12 13:06:06 2009 +0100 +++ b/src/mappers.cc Mon Jan 12 14:03:28 2009 +0100 @@ -807,12 +807,12 @@ %!assert(imag (1), 0); %!assert(imag (i), 1); %!assert(imag (1+i), 1); -%!assert(imag ([i, 1; 1, i]), eye (2)(:,:)); +%!assert(imag ([i, 1; 1, i]), full (eye (2))); %!assert(imag (single(1)), single(0)); %!assert(imag (single(i)), single(1)); %!assert(imag (single(1+i)), single(1)); -%!assert(imag (single([i, 1; 1, i])), eye (2,'single')(:,:)); +%!assert(imag (single([i, 1; 1, i])), full (eye (2,'single'))); %!error imag (); %!error imag (1, 2); @@ -1254,12 +1254,12 @@ %!assert(real (1), 1); %!assert(real (i), 0); %!assert(real (1+i), 1); -%!assert(real ([1, i; i, 1]), eye (2)(:,:)); +%!assert(real ([1, i; i, 1]), full (eye (2))); %!assert(real (single(1)), single(1)); %!assert(real (single(i)), single(0)); %!assert(real (single(1+i)), single(1)); -%!assert(real (single([1, i; i, 1])), eye (2,'single')(:,:)); +%!assert(real (single([1, i; i, 1])), full (eye (2,'single'))); %!error real (); %!error real (1, 2); diff -r d254a21e0120 -r d17874a6f161 src/ov-base-diag.cc --- a/src/ov-base-diag.cc Mon Jan 12 13:06:06 2009 +0100 +++ b/src/ov-base-diag.cc Mon Jan 12 14:03:28 2009 +0100 @@ -86,8 +86,6 @@ // 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. - // Note that, for better consistency, eye(n)(:,:) still converts to a full - // matrix. // FIXME: This check is probably unnecessary for complex matrices. if (! error_state && nidx == 2 && matrix.is_multiple_of_identity (one)) { @@ -108,6 +106,11 @@ else if (right) retval = octave_value (PermMatrix (idx1, true), is_single_type ()); + else + { + retval = this; + this->count++; + } } } @@ -120,6 +123,20 @@ // FIXME: the proxy mechanism of DiagArray2 causes problems here. retval = el_type (matrix.checkelem (idx0(0), idx1(0))); } + else if (nidx == 2 && ! resize_ok) + { + octave_idx_type m = idx0.length (matrix.rows ()); + octave_idx_type n = idx1.length (matrix.columns ()); + if (idx0.is_colon_equiv (m) && idx1.is_colon_equiv (n) + && m <= matrix.rows () && n <= matrix.rows ()) + { + DMT rm (matrix); + rm.resize (m, n); + retval = rm; + } + else + retval = to_dense ().do_index_op (idx, resize_ok); + } else retval = to_dense ().do_index_op (idx, resize_ok); } diff -r d254a21e0120 -r d17874a6f161 src/ov-perm.cc --- a/src/ov-perm.cc Mon Jan 12 13:06:06 2009 +0100 +++ b/src/ov-perm.cc Mon Jan 12 14:03:28 2009 +0100 @@ -99,6 +99,11 @@ p = p * PermMatrix (idx1, true); retval = octave_value (p, is_single_type ()); } + else + { + retval = this; + this->count++; + } } }