Mercurial > hg > octave-lojdl
changeset 10494:e52f41fd82c7
optimize (:) indexing of sparse column vectors
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 07 Apr 2010 13:00:25 +0200 |
parents | 2f8bacc2a57d |
children | f7d8b2bd7b57 |
files | liboctave/ChangeLog liboctave/Sparse.cc |
diffstat | 2 files changed, 20 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-04-07 Jaroslav Hajek <highegg@gmail.com> + + * Sparse.cc (Sparse<T>::index (const idx_vector&, bool)): Use shallow + copy when column is indexed by colon. + 2010-04-07 Jaroslav Hajek <highegg@gmail.com> * Sparse.cc (lblookup): Move in front of Sparse<T>::delete_elements.
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -1472,20 +1472,25 @@ ("cannot index sparse matrix with an N-D Array"); else if (idx.is_colon ()) { - // Fast magic colon processing. - retval = Sparse<T> (nel, 1, nz); - - for (octave_idx_type i = 0; i < nc; i++) + if (nc == 1) + retval = *this; + else { - for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) + // Fast magic colon processing. + retval = Sparse<T> (nel, 1, nz); + + for (octave_idx_type i = 0; i < nc; i++) { - retval.xdata(j) = data(j); - retval.xridx(j) = ridx(j) + i * nr; + for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) + { + retval.xdata(j) = data(j); + retval.xridx(j) = ridx(j) + i * nr; + } } + + retval.xcidx(0) = 0; + retval.xcidx(1) = nz; } - - retval.xcidx(0) = 0; - retval.xcidx(1) = nz; } else if (idx.extent (nel) > nel) {