# HG changeset patch # User jwe # Date 1069718352 0 # Node ID e3da702f75029f36a356722f9e8777f2cb9a1585 # Parent c8829691db47b19871a7ff340f9da07f1cdac1ef [project @ 2003-11-24 23:59:12 by jwe] diff --git a/liboctave/Array.cc b/liboctave/Array.cc --- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2546,11 +2546,47 @@ ("number of indices is zero"); else if (n_idx == 1) { - Array 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); diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,5 +1,7 @@ 2003-11-24 John W. Eaton + * Array.cc (assignN): Allow single indexing to work for scalar RHS. + * dim-vector.h (dim_vector::all_ones): New function. 2003-11-23 John W. Eaton