# HG changeset patch # User Jaroslav Hajek # Date 1263416818 -3600 # Node ID d3451c1496f846fad0f520cabba0bd0bb2f29bdf # Parent 462fa695a565624426e343c6d04094d56a067071 allow the general case in Array::compute_index diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -168,23 +168,18 @@ octave_idx_type Array::compute_index (const Array& 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::compute_index: invalid ra_idxing operation"); return retval; } diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-01-13 Jaroslav Hajek + + * Array.cc (Array::compute_index): Generalize to the case of + unequal lengths. + 2010-01-13 Jaroslav Hajek * dim-vector.h (dim_vector::chop_trailing_singletons): Only uniquify