Mercurial > hg > octave-lyh
changeset 9351:e2344f4af0cb
autocache indices returned from find et al.
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 15 Jun 2009 12:52:53 +0200 |
parents | 16a5f9e1fdb3 |
children | b59cc3252a51 |
files | src/ChangeLog src/DLD-FUNCTIONS/find.cc src/DLD-FUNCTIONS/lookup.cc src/DLD-FUNCTIONS/max.cc src/data.cc src/ov-re-mat.h src/ov.cc src/ov.h |
diffstat | 8 files changed, 43 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2009-06-15 Jaroslav Hajek <highegg@gmail.com> + + * ov-re-mat.h (octave_matrix::octave_matrix (const Array<octave_idx_type>&, + bool)): New constructor. + * ov.cc (octave_value::octave_value (const Array<octave_idx_type>&, + bool)): New constructor. + * ov.h: Declare it. + + * data.cc (Fsort, F__sort_rows_idx__): Use the new constructor. + * DLD-FUNCTIONS/find.cc (Ffind): Ditto. + * DLD-FUNCTIONS/lookup.cc (Flookup): Ditto. + * DLD-FUNCTIONS/max.cc (Fmax, Fmin, Fcummax, Fcummin): Ditto. + 2009-06-15 Jaroslav Hajek <highegg@gmail.com> * ov-base-mat.h (octave_base_matrix::idx_cache): New member field.
--- a/src/DLD-FUNCTIONS/find.cc +++ b/src/DLD-FUNCTIONS/find.cc @@ -65,13 +65,13 @@ jdx.xelem (i) = idx.xelem (i) / nr; idx.xelem (i) %= nr; } - retval(1) = NDArray (jdx, true); + retval(1) = octave_value (jdx, true, true); } // Fall through! case 1: case 0: - retval(0) = NDArray (idx, true); + retval(0) = octave_value (idx, true, true); break; }
--- a/src/DLD-FUNCTIONS/lookup.cc +++ b/src/DLD-FUNCTIONS/lookup.cc @@ -125,7 +125,9 @@ else idx = array.lookup (values, UNSORTED, left_inf, right_inf); - retval = NDArray (idx, match_idx); + // if left_inf is specified, the result is a valid 1-based index. + bool cache_index = left_inf && array.numel () > 1; + retval = octave_value (idx, match_idx, cache_index); } return retval; @@ -314,7 +316,7 @@ str_y.nelem (), idx.fortran_vec ()); } - retval = NDArray (idx, match_idx); + retval = octave_value (idx, match_idx); } } else
--- a/src/DLD-FUNCTIONS/max.cc +++ b/src/DLD-FUNCTIONS/max.cc @@ -99,7 +99,7 @@ octave_idx_type len = index.numel (); \ \ if (len > 0) \ - retval(1) = NDArray (index, true, true); \ + retval(1) = octave_value (index, true, true); \ else \ retval(1) = NDArray (); \ } \ @@ -266,7 +266,7 @@ octave_idx_type len = index.numel (); \ \ if (len > 0) \ - retval(1) = NDArray (index, true, true); \ + retval(1) = octave_value (index, true, true); \ else \ retval(1) = NDArray (); \ } \ @@ -403,7 +403,7 @@ octave_idx_type len = index.numel (); \ \ if (len > 0) \ - retval(1) = NDArray (index, true, true); \ + retval(1) = octave_value (index, true, true); \ else \ retval(1) = NDArray (); \ } \ @@ -489,7 +489,7 @@ octave_idx_type len = index.numel (); \ \ if (len > 0) \ - retval(1) = NDArray (index, true, true); \ + retval(1) = octave_value (index, true, true); \ else \ retval(1) = NDArray (); \ } \
--- a/src/data.cc +++ b/src/data.cc @@ -5628,7 +5628,7 @@ Array<octave_idx_type> sidx; retval (0) = arg.sort (sidx, dim, smode); - retval (1) = NDArray (sidx, true); + retval (1) = octave_value (sidx, true, true); } else retval(0) = arg.sort (dim, smode); @@ -5858,7 +5858,7 @@ { Array<octave_idx_type> idx = arg.sort_rows_idx (smode); - retval = NDArray (idx, true); + retval = octave_value (idx, true, true); } else error ("__sort_rows_idx__: needs a 2-dimensional object");
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -81,6 +81,15 @@ octave_matrix (const octave_matrix& m) : octave_base_matrix<NDArray> (m) { } + octave_matrix (const Array<octave_idx_type>& idx, + bool zero_based = false, bool cache_index = false) + : octave_base_matrix<NDArray> (NDArray (idx, zero_based)) + { + // Auto-create cache to speed up subsequent indexing. + if (zero_based && cache_index) + set_idx_cache (idx_vector (idx)); + } + ~octave_matrix (void) { } octave_base_value *clone (void) const { return new octave_matrix (*this); }
--- a/src/ov.cc +++ b/src/ov.cc @@ -974,6 +974,13 @@ maybe_mutate (); } +octave_value::octave_value (const Array<octave_idx_type>& inda, bool zero_based, + bool cache_index) + : rep (new octave_matrix (inda, zero_based, cache_index)) +{ + maybe_mutate (); +} + octave_value::octave_value (double base, double limit, double inc) : rep (new octave_range (base, limit, inc)) {
--- a/src/ov.h +++ b/src/ov.h @@ -261,6 +261,8 @@ octave_value (const ArrayN<octave_uint32>& inda); octave_value (const uint64NDArray& inda); octave_value (const ArrayN<octave_uint64>& inda); + octave_value (const Array<octave_idx_type>& inda, + bool zero_based = false, bool cache_index = false); octave_value (double base, double limit, double inc); octave_value (const Range& r); octave_value (const Octave_map& m);