Mercurial > hg > octave-lyh
changeset 8384:a99b9113c58c
optimize sparse bool indexing
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 08 Dec 2008 15:33:28 +0100 |
parents | a762d9daa700 |
children | 6e9660cd3bf2 |
files | liboctave/ChangeLog liboctave/idx-vector.cc liboctave/idx-vector.h |
diffstat | 3 files changed, 48 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,12 @@ +2008-12-08 Jaroslav Hajek <highegg@gmail.com> + + * idx-vector.cc (idx_vector::idx_vector_rep::idx_vector_rep (const + Sparse<bool>&)): New constructor. + * idx_vector.h: Declare it. + (idx_vector::idx_vector (const Sparse<bool>&)): New constructor. + * idx-vector.cc (idx_vector::idx_vector_rep::idx_vector_rep (const + Array<bool>&)): Fix extent calculation. + 2008-12-07 Jaroslav Hajek <highegg@gmail.com> * mx-inlines.cc (mx_inline_fill_vs): New template function.
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -32,6 +32,7 @@ #include "idx-vector.h" #include "Array.h" +#include "Sparse.h" #include "Range.h" #include "oct-locbuf.h" @@ -312,7 +313,38 @@ data = d; - ext = k; + ext = d[k-1] + 1; + } +} + +idx_vector::idx_vector_rep::idx_vector_rep (const Sparse<bool>& bnda) + : data (0), len (0), ext (0), aowner (0), orig_dims () +{ + for (octave_idx_type i = 0, l = bnda.nnz (); i < l; i++) + if (bnda.data (i)) len++; + + dim_vector dv = bnda.dims (); + + orig_dims = ((dv.length () == 2 && dv(0) == 1) + ? dim_vector (1, len) : orig_dims = dim_vector (len, 1)); + + if (len != 0) + { + octave_idx_type *d = new octave_idx_type [len]; + + octave_idx_type nnz = bnda.nnz (); + + octave_idx_type k = 0; + // FIXME: I hope this is OK, i.e. the element iterated this way are correctly ordered. + for (octave_idx_type i = 0; i < nnz; i++) + { + if (bnda.data (i)) + d[k++] = bnda.cidx (i) + bnda.rows () * bnda.ridx (i); + } + + data = d; + + ext = d[k-1] + 1; } }
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -33,6 +33,7 @@ #include "oct-inttypes.h" template<class T> class Array; +template<class T> class Sparse; class Range; // Design rationale: @@ -270,6 +271,8 @@ idx_vector_rep (const Array<bool>&); + idx_vector_rep (const Sparse<bool>&); + ~idx_vector_rep (void); octave_idx_type xelem (octave_idx_type i) const @@ -397,6 +400,9 @@ : rep (new idx_range_rep (r)) { chkerr (); } + idx_vector (const Sparse<bool>& nda) : rep (new idx_vector_rep (nda)) + { chkerr (); } + idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; } ~idx_vector (void)