Mercurial > hg > octave-nkf
changeset 5264:95e054384359
[project @ 2005-04-01 18:22:37 by jwe]
author | jwe |
---|---|
date | Fri, 01 Apr 2005 18:22:37 +0000 |
parents | c83fda7b2c4c |
children | 86185152b7a4 |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 32 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -3003,23 +3003,37 @@ dim_vector new_dims; new_dims.resize (n_idx); - for (int i = 0; i < n_idx; i++) + if (orig_empty) { - if (orig_empty) + int k = 0; + for (int i = 0; i < n_idx; i++) { // If index is a colon, resizing to RHS dimensions is // allowed because we started out empty. - new_dims(i) - = (i < rhs_dims.length () && idx(i).is_colon ()) - ? rhs_dims(i) : idx(i).max () + 1; + if (idx(i).is_colon ()) + { + if (k < rhs_dims.length ()) + new_dims(i) = rhs_dims(k++); + else + { + (*current_liboctave_error_handler) + ("A(IDX-LIST) = RHS: A previously undefined and more colons in IDX-LIST than dimensions for RHS"); + return retval; + } + } + else + new_dims(i) = idx(i).max () + 1; } - else + } + else + { + for (int i = 0; i < n_idx; i++) { // We didn't start out with all zero dimensions, so if // index is a colon, it refers to the current LHS // dimension. Otherwise, it is OK to enlarge to a - // dimension given by the largest index, but if that + // dimension given by the largest index, but if that // index is a colon the new dimension is singleton. if (i < lhs_dims_len @@ -3095,33 +3109,9 @@ { // RHS is matrix or higher dimension. - // Check that non-singleton RHS dimensions conform to - // non-singleton LHS index dimensions. - - dim_vector t_rhs_dims = rhs_dims.squeeze (); - dim_vector t_frozen_len = frozen_len.squeeze (); - - // If after sqeezing out singleton dimensions, RHS is - // vector and LHS is vector, force them to have the same - // orientation so that operations like - // - // a = zeros (3, 3, 3); - // a(1:3,1,1) = [1,2,3]; - // - // will work. - - if (t_rhs_dims.length () == 2 && t_frozen_len.length () == 2 - && ((t_rhs_dims.elem(1) == 1 - && t_frozen_len.elem(0) == 1) - || (t_rhs_dims.elem(0) == 1 - && t_frozen_len.elem(1) == 1))) - { - int t0 = t_rhs_dims.elem(0); - t_rhs_dims.elem(0) = t_rhs_dims.elem(1); - t_rhs_dims.elem(1) = t0; - } - - if (t_rhs_dims != t_frozen_len) + int n = Array<LT>::get_size (frozen_len); + + if (n != rhs.numel ()) { (*current_liboctave_error_handler) ("A(IDX-LIST) = X: X must be a scalar or size of X must equal number of elements indexed by IDX-LIST");
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2005-04-01 John W. Eaton <jwe@octave.org> + + * Array.cc (assignN): For A(IDX-LIST) = RHS with A previously + undefined, correctly match colons in IDX-LIST with RHS dimensions + when resizing A. When performing the assignment, just check that + the number of elements in RHS matches the number of elements + indexed by IDX-LIST. + 2005-03-30 John W. Eaton <jwe@octave.org> * lo-mappers.cc (log10, tan, tanh): Delete functions.