# HG changeset patch # User jwe # Date 1069723809 0 # Node ID a585a2dfca6cfb0f82e51898b45bec3787ffe0fb # Parent e3da702f75029f36a356722f9e8777f2cb9a1585 [project @ 2003-11-25 01:30:09 by jwe] diff -r e3da702f7502 -r a585a2dfca6c liboctave/Array.cc --- a/liboctave/Array.cc Mon Nov 24 23:59:12 2003 +0000 +++ b/liboctave/Array.cc Tue Nov 25 01:30:09 2003 +0000 @@ -2539,53 +2539,57 @@ { lhs.maybe_delete_elements (idx, rfv); } - else if (rhs_is_scalar) + else if (n_idx == 1) { - if (n_idx == 0) - (*current_liboctave_error_handler) - ("number of indices is zero"); - else if (n_idx == 1) + idx_vector iidx = idx(0); + + if (liboctave_wfi_flag + && ! (iidx.is_colon () + || (iidx.one_zero_only () + && iidx.orig_dimensions () == lhs.dims ()))) + (*current_liboctave_warning_handler) + ("single index used for n-d array"); + + int lhs_len = lhs.length (); + + int len = iidx.freeze (lhs_len, "n-d arrray"); + + if (iidx) { - idx_vector iidx = idx(0); - - if (liboctave_wfi_flag - && ! (iidx.is_colon () - || (iidx.one_zero_only () - && iidx.orig_dimensions () == lhs.dims ()))) - (*current_liboctave_warning_handler) - ("single index used for n-d array"); - - int lhs_len = lhs.length (); - - int len = iidx.freeze (lhs_len, "n-d arrray"); - - if (iidx) + if (len == 0) { - if (len == 0) - { - if (! (rhs_dims.all_ones () || rhs_dims.all_zero ())) - (*current_liboctave_error_handler) - ("A([]) = X: X must be an empty matrix or scalar"); - } - else if (len <= lhs_len) + if (! (rhs_dims.all_ones () || rhs_dims.all_zero ())) + (*current_liboctave_error_handler) + ("A([]) = X: X must be an empty matrix or scalar"); + } + else if (len == rhs.length ()) + { + for (int i = 0; i < len; i++) { - RT scalar = rhs.elem (0); - - for (int i = 0; i < len; i++) - { - int ii = iidx.elem (i); - - lhs.elem (ii) = scalar; - } - } - else - { - (*current_liboctave_error_handler) - ("A(I) = X: X must be a scalar or a matrix with the same size as I"); - - retval = 0; + int ii = iidx.elem (i); + + lhs.elem (ii) = rhs.elem (i); } } + else if (rhs_is_scalar && len <= lhs_len) + { + RT scalar = rhs.elem (0); + + for (int i = 0; i < len; i++) + { + int ii = iidx.elem (i); + + lhs.elem (ii) = scalar; + } + } + else + { + (*current_liboctave_error_handler) + ("A(I) = X: X must be a scalar or a matrix with the same size as I"); + + retval = 0; + } + // idx_vector::freeze() printed an error message for us. } else if (n_idx < lhs_dims.length ()) @@ -2839,7 +2843,7 @@ // 2D info: // - // << prefix << "rows: " << rows () << "\n" + // << pefix << "rows: " << rows () << "\n" // << prefix << "cols: " << cols () << "\n"; } diff -r e3da702f7502 -r a585a2dfca6c liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Nov 24 23:59:12 2003 +0000 +++ b/liboctave/ChangeLog Tue Nov 25 01:30:09 2003 +0000 @@ -1,6 +1,6 @@ 2003-11-24 John W. Eaton - * Array.cc (assignN): Allow single indexing to work for scalar RHS. + * Array.cc (assignN): Allow single indexing to work. * dim-vector.h (dim_vector::all_ones): New function.