Mercurial > hg > octave-terminal
changeset 10327:76cf6dd20f1a
take advantage of lazy index optimization in lookup
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 17 Feb 2010 08:29:17 +0100 |
parents | ade59ae10e80 |
children | 2210d3070543 |
files | src/ChangeLog src/DLD-FUNCTIONS/lookup.cc |
diffstat | 2 files changed, 25 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-02-17 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/lookup.cc (do_numeric_lookup): Return an idx_vector + when left_inf is in effect, to enable lazy index optimization. + 2010-02-16 Jaroslav Hajek <highegg@gmail.com> * ov-lazy-idx.h: New source.
--- a/src/DLD-FUNCTIONS/lookup.cc +++ b/src/DLD-FUNCTIONS/lookup.cc @@ -131,43 +131,54 @@ } else if (match_idx || left_inf || right_inf) { - NDArray ridx (idx.dims ()); if (match_idx) { + NDArray ridx (idx.dims ()); + for (octave_idx_type i = 0; i < nval; i++) { octave_idx_type j = idx.xelem (i); ridx.xelem (i) = (j != 0 && values(i) == array(j-1)) ? j : 0; } + + retval = ridx; } else if (left_inf && right_inf) { + // Results in valid indices. Optimize using lazy index. + octave_idx_type zero = 0; for (octave_idx_type i = 0; i < nval; i++) { - octave_idx_type one = 1; - octave_idx_type j = idx.xelem (i); - ridx.xelem (i) = std::min (std::max (one, j), n-1); + octave_idx_type j = idx.xelem (i) - 1; + idx.xelem (i) = std::max (zero, std::min (j, n-2)); } + + retval = idx_vector (idx); } else if (left_inf) { - octave_idx_type one = 1; + // Results in valid indices. Optimize using lazy index. + octave_idx_type zero = 0; for (octave_idx_type i = 0; i < nval; i++) { - octave_idx_type j = idx.xelem (i); - ridx.xelem (i) = std::max (one, j); + octave_idx_type j = idx.xelem (i) - 1; + idx.xelem (i) = std::max (zero, j); } + + retval = idx_vector (idx); } else if (right_inf) { + NDArray ridx (idx.dims ()); + for (octave_idx_type i = 0; i < nval; i++) { octave_idx_type j = idx.xelem (i); ridx.xelem (i) = std::min (j, n-1); } + + retval = ridx; } - - retval = ridx; } else retval = idx;