# HG changeset patch # User jwe # Date 1069637056 0 # Node ID b868b39534b0d102566d0d2bb0d3004f4672e51c # Parent 623f6262a8e9d89c84fd261c466c0f1c67825fb7 [project @ 2003-11-24 01:24:16 by jwe] diff -r 623f6262a8e9 -r b868b39534b0 liboctave/Array.cc --- a/liboctave/Array.cc Sun Nov 23 23:17:47 2003 +0000 +++ b/liboctave/Array.cc Mon Nov 24 01:24:16 2003 +0000 @@ -1803,9 +1803,9 @@ if (ra_idx.is_colon ()) { - dim_vector iidx (orig_len); - - retval = Array (*this, iidx); + // Fast magic colon processing. + + retval = Array (*this, dim_vector (orig_len, 1)); } else if (length () == 1) { @@ -1868,11 +1868,14 @@ ("I do not know what to do here yet!"); } } - else if (liboctave_wfi_flag || - (ra_idx.one_zero_only () && equal_arrays (idx_orig_dims, dims ()))) + else { - // This code is only for indexing nd-arrays. The vector - // cases are handled above. + if (liboctave_wfi_flag + && ! (ra_idx.is_colon () + || (ra_idx.one_zero_only () + && equal_arrays (idx_orig_dims, dims ())))) + (*current_liboctave_warning_handler) + ("single index used for N-d array"); ra_idx.freeze (orig_len, "nd-array", resize_ok); @@ -1882,15 +1885,10 @@ if (ra_idx.one_zero_only ()) { - for (int i = 0; i < result_dims.length(); i++) - { - if (i == 0) - result_dims(i) = ra_idx.ones_count (); - else if (result_dims(0) > 0) - result_dims(i) = 1; - else - result_dims(i) = 0; - } + result_dims.resize (2); + int ntot = ra_idx.ones_count (); + result_dims(0) = ntot; + result_dims(1) = (ntot > 0 ? 1 : 0); } retval.resize (result_dims); @@ -1920,36 +1918,6 @@ } } } - else if (ra_idx.capacity () == 1) - { - // i.e. A(8) for A(3x3x3) - - ra_idx.freeze (orig_len, "nd-array", resize_ok); - - if (ra_idx) - { - int r_idx = ra_idx(0); - - Array iidx = get_ra_idx (r_idx, dims ()); - - dim_vector new_dims (1); - - // This shouldn't be needed. - - Array e (iidx.length ()); - - for (int i = 0; i < iidx.length();i++) - e(i) = iidx(i); - - // Should be able to call elem (iidx). - - retval = Array (new_dims, elem (e)); - } - } - else - (*current_liboctave_error_handler) - ("single index only valid for row or column vector. ra_idx.cap () = &d", - ra_idx.capacity ()); return retval; } diff -r 623f6262a8e9 -r b868b39534b0 liboctave/ChangeLog --- a/liboctave/ChangeLog Sun Nov 23 23:17:47 2003 +0000 +++ b/liboctave/ChangeLog Mon Nov 24 01:24:16 2003 +0000 @@ -1,5 +1,9 @@ 2003-11-23 John W. Eaton + * Array.cc (Array::indexN): Correctly handle single colon index. + Omit special case for ra_idx.capacity () == 1. + Always allow single index for matrix args with optional warning. + * idx-vector.h, idx-vector.cc: Convert boolMatrix functions to use boolNDArray. Likewise, convert Matrix functions to use NDArray.