Mercurial > hg > octave-terminal
changeset 8459:d17874a6f161
improve indexing of diagonal & permutation matrices
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Jan 2009 14:03:28 +0100 |
parents | d254a21e0120 |
children | e4c9ecb64411 |
files | src/ChangeLog src/data.cc src/mappers.cc src/ov-base-diag.cc src/ov-perm.cc |
diffstat | 5 files changed, 44 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2009-01-12 Jaroslav Hajek <highegg@gmail.com> + + * 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 <highegg@gmail.com> * 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 <highegg@gmail.com> * ov.h (octave_value::is_copy_of): New method.
--- a/src/data.cc +++ b/src/data.cc @@ -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]));
--- a/src/mappers.cc +++ b/src/mappers.cc @@ -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);
--- a/src/ov-base-diag.cc +++ b/src/ov-base-diag.cc @@ -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); }