Mercurial > hg > octave-nkf
diff liboctave/Array.cc @ 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 | eb8ac0eed9f1 |
children | 5aff7f14aa7f |
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; }