Mercurial > hg > octave-terminal
changeset 12184:d8de1a28274c
sparse matrix indexed assignment bug
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 27 Jan 2011 16:46:50 -0500 |
parents | b4d26c65e7e6 |
children | 862a8e490445 |
files | liboctave/ChangeLog liboctave/Sparse.cc |
diffstat | 2 files changed, 44 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2011-01-27 John W. Eaton <jwe@octave.org> + + * Sparse.cc (Sparse<T>::assign (const idx_vector&, const idx_vector&, + const Sparse<T>&)): Allow 0x0 LHS with colon dimensions to + inherit dimensions from RHS. Fix tests. Bug #32263. + 2011-01-26 John W. Eaton <jwe@octave.org> * oct-refcount.h: Strip trailing whitespace.
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -1858,12 +1858,39 @@ octave_idx_type n = rhs.rows (); octave_idx_type m = rhs.columns (); - if (idx_i.length (nr) == n && idx_j.length (nc) == m) + // FIXME -- this should probably be written more like the + // Array<T>::assign function... + + bool orig_zero_by_zero = (nr == 0 && nc == 0); + + if (orig_zero_by_zero || (idx_i.length (nr) == n && idx_j.length (nc) == m)) { - if (n == 0 || m == 0) - return; + octave_idx_type nrx; + octave_idx_type ncx; + + if (orig_zero_by_zero) + { + if (idx_i.is_colon ()) + { + nrx = n; - octave_idx_type nrx = idx_i.extent (nr), ncx = idx_j.extent (nc); + if (idx_j.is_colon ()) + ncx = n; + else + ncx = idx_j.extent (nc); + } + else if (idx_j.is_colon ()) + { + nrx = idx_i.extent (nr); + ncx = m; + } + } + else + { + nrx = idx_i.extent (nr); + ncx = idx_j.extent (nc); + } + // Try to resize first if necessary. if (nrx != nr || ncx != nc) { @@ -1873,6 +1900,9 @@ // nz is preserved. } + if (n == 0 || m == 0) + return; + if (idx_i.is_colon ()) { octave_idx_type lb, ub; @@ -2599,8 +2629,8 @@ %!test test_sparse_slice([2 0], 21, 1); %!test test_sparse_slice([2 0], 21, 2); %!test test_sparse_slice([2 0], 21, [2,2]); -%!assert(set_slice(sparse(ones([2 0])), 21, 3), sparse(2,0)); # sparse different from full -%!assert(set_slice(sparse(ones([2 0])), 21, 4), sparse(2,0)); # sparse different from full +%!assert(set_slice(sparse(ones([2 0])), 21, 3), sparse(3,0)); +%!assert(set_slice(sparse(ones([2 0])), 21, 4), sparse(4,0)); %!test test_sparse_slice([2 0], 22, []); %!test test_sparse_slice([2 0], 22, 1); %!test test_sparse_slice([2 0], 22, 2); @@ -2619,8 +2649,8 @@ %!test test_sparse_slice([0 2], 22, 1); %!test test_sparse_slice([0 2], 22, 2); %!test test_sparse_slice([0 2], 22, [2,2]); -%!assert(set_slice(sparse(ones([0 2])), 22, 3), sparse(0,2)); # sparse different from full -%!assert(set_slice(sparse(ones([0 2])), 22, 4), sparse(0,2)); # sparse different from full +%!assert(set_slice(sparse(ones([0 2])), 22, 3), sparse(0,3)); +%!assert(set_slice(sparse(ones([0 2])), 22, 4), sparse(0,4)); ## size = [2 1] %!test test_sparse_slice([2 1], 21, []);