Mercurial > hg > octave-nkf
diff liboctave/Array.cc @ 4656:e3da702f7502
[project @ 2003-11-24 23:59:12 by jwe]
author | jwe |
---|---|
date | Mon, 24 Nov 2003 23:59:12 +0000 |
parents | 14ab7b05a572 |
children | a585a2dfca6c |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2546,11 +2546,47 @@ ("number of indices is zero"); else if (n_idx == 1) { - Array<int> one_arg_temp (1, 0); - - RT scalar = rhs.elem (one_arg_temp); - - lhs.fill (scalar); + 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 (! (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) + { + 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 ()) { @@ -2755,7 +2791,7 @@ if (index_in_bounds (elt_idx, lhs_inc)) { - int s = compute_index (result_rhs_idx,rhs_dims); + int s = compute_index (result_rhs_idx, rhs_dims); lhs.checkelem (elt_idx) = rhs.elem (s);