# HG changeset patch # User John W. Eaton # Date 1296164810 18000 # Node ID 9086df10c460484f1c67cdbd55b0ffa3c33cba5f # Parent c626741871a0d8bbbd3ed7c63cb45fa82cb7f0ee sparse matrix indexed assignment bug diff -r c626741871a0 -r 9086df10c460 liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Jan 27 17:58:19 2011 +0100 +++ b/liboctave/ChangeLog Thu Jan 27 16:46:50 2011 -0500 @@ -1,3 +1,9 @@ +2011-01-27 John W. Eaton + + * Sparse.cc (Sparse::assign (const idx_vector&, const idx_vector&, + const Sparse&)): Allow 0x0 LHS with colon dimensions to + inherit dimensions from RHS. Fix tests. Bug #32263. + 2011-01-26 John W. Eaton * oct-refcount.h: Strip trailing whitespace. diff -r c626741871a0 -r 9086df10c460 liboctave/Sparse.cc --- a/liboctave/Sparse.cc Thu Jan 27 17:58:19 2011 +0100 +++ b/liboctave/Sparse.cc Thu Jan 27 16:46:50 2011 -0500 @@ -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::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, []);