Mercurial > hg > octave-lyh
changeset 14656:8d2ce821e38a
Ensure sparse constructors have valid ridx and data indices even if they are zero matrices (bug #36104)
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sat, 19 May 2012 01:59:21 +0200 |
parents | 43db83eff9db |
children | 8a84849ad986 |
files | liboctave/Sparse.cc |
diffstat | 1 files changed, 5 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -235,7 +235,7 @@ (*current_liboctave_error_handler) ("Sparse::Sparse (const dim_vector&): dimension mismatch"); else - rep = new typename Sparse<T>::SparseRep (dv(0), dv(1)); + rep = new typename Sparse<T>::SparseRep (dv(0), dv(1), 0); } template <class T> @@ -301,11 +301,10 @@ (*current_liboctave_error_handler) ("sparse: column index %d out of bound %d", r.extent (nc), nc); - rep = new SparseRep (nr, nc); + rep = new typename Sparse<T>::SparseRep (nr, nc, (nzm > 0 ? nzm : 0)); dimensions = dim_vector (nr, nc); - octave_idx_type n = a.numel (), rl = r.length (nr), cl = c.length (nc); bool a_scalar = n == 1; if (a_scalar) @@ -324,6 +323,7 @@ if (n == 1 && a(0) != T ()) { change_capacity (nzm > 1 ? nzm : 1); + xcidx(0) = 0; xridx(0) = r(0); xdata(0) = a(0); for (octave_idx_type j = 0; j < nc; j++) @@ -352,6 +352,7 @@ new_nz += rd[i-1] != rd[i]; // Allocate result. change_capacity (nzm > new_nz ? nzm : new_nz); + xcidx (0) = 0; xcidx (1) = new_nz; octave_idx_type *rri = ridx (); T *rrd = data (); @@ -494,6 +495,7 @@ new_nz += rd[i-1] != rd[i]; // Allocate result. change_capacity (nzm > new_nz ? nzm : new_nz); + xcidx(0) = 0; xcidx(1) = new_nz; octave_idx_type *rri = ridx (); T *rrd = data ();