Mercurial > hg > octave-max
changeset 10098:d3451c1496f8
allow the general case in Array<T>::compute_index
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 13 Jan 2010 22:06:58 +0100 |
parents | 462fa695a565 |
children | 29959c705df2 |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 15 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -168,23 +168,18 @@ octave_idx_type Array<T>::compute_index (const Array<octave_idx_type>& ra_idx) const { - octave_idx_type retval = -1; - - int n = dimensions.length (); - - if (n > 0 && n == ra_idx.length ()) + octave_idx_type retval = 0; + + int n = dimensions.length (), ni = ra_idx.length (); + + while (ni > n) + retval += ra_idx(--ni); + + while (ni > 0) { - retval = ra_idx(--n); - - while (--n >= 0) - { - retval *= dimensions(n); - retval += ra_idx(n); - } + retval *= dimensions(--ni); + retval += ra_idx(ni); } - else - (*current_liboctave_error_handler) - ("Array<T>::compute_index: invalid ra_idxing operation"); return retval; }
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-01-13 Jaroslav Hajek <highegg@gmail.com> + + * Array.cc (Array<T>::compute_index): Generalize to the case of + unequal lengths. + 2010-01-13 Jaroslav Hajek <highegg@gmail.com> * dim-vector.h (dim_vector::chop_trailing_singletons): Only uniquify