Mercurial > hg > octave-lyh
changeset 11571:0e414f837c58
Fix indexing error in the construction of sparse matrices
author | David Bateman <dbateman@free.fr> |
---|---|
date | Thu, 20 Jan 2011 02:46:51 +0100 |
parents | 57632dea2446 |
children | 7d6d8c1e471f |
files | liboctave/ChangeLog liboctave/Sparse.cc liboctave/boolSparse.cc |
diffstat | 3 files changed, 23 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,13 @@ +2011-01-20 David Bateman <dbateman@free.fr> + + * Sparce.cc (template <class T> Sparse<T>::Sparse (const Array<T>&, + const idx_vector&, const idx_vector&, octave_idx_type, + octave_idx_type, bool, octave_idx_type): Fix off by one error in the + construction of sparse column vectors. Fix indexing issue in + construction of sparse row vectors. + * boolSparse.cc (SparseBoolMatrix SparseBoolMatrix::any (int) const): + Fully initialize cidx for any called on the first dimension. + 2011-01-19 John W. Eaton <jwe@octave.org> * Array.h (explicit Array (octave_idx_type, const T&)):
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -350,13 +350,13 @@ else { // Pick the last one. - for (octave_idx_type i = 1; i < n; i++) + for (octave_idx_type i = 0; i < n; i++) { if (rd[i] != l) { l = rd[i]; - rrd[++k] = a0; - rri[k] = rd[i]; + rri[++k] = rd[i]; + rrd[k] = a0; } } } @@ -384,7 +384,10 @@ // Bucket sort. OCTAVE_LOCAL_BUFFER (octave_idx_type, sidx, n); for (octave_idx_type i = 0; i < n; i++) - sidx[ci[cd[i]+1]++] = rd[i]; + if (rl == 1) + sidx[ci[cd[i]+1]++] = rd[0]; + else + sidx[ci[cd[i]+1]++] = rd[i]; // Subsorts. We don't need a stable sort, all values are equal. xcidx(0) = 0; @@ -525,7 +528,10 @@ for (octave_idx_type i = 0; i < n; i++) { idx_pair& p = spairs[ci[cd[i]+1]++]; - p.first = rd[i]; + if (rl == 1) + p.first = rd[0]; + else + p.first = rd[i]; p.second = i; }
--- a/liboctave/boolSparse.cc +++ b/liboctave/boolSparse.cc @@ -150,7 +150,8 @@ { // Result is a row vector. retval = Sparse<bool> (1, nc); - for(octave_idx_type i = 0; i < nc; i++) + retval.xcidx(0) = 0; + for (octave_idx_type i = 0; i < nc; i++) retval.xcidx(i+1) = retval.xcidx(i) + (cidx(i+1) > cidx(i)); octave_idx_type new_nz = retval.xcidx(nc); retval.change_capacity (new_nz);