changeset 4656:e3da702f7502

[project @ 2003-11-24 23:59:12 by jwe]
author jwe
date Mon, 24 Nov 2003 23:59:12 +0000
parents c8829691db47
children a585a2dfca6c
files liboctave/Array.cc liboctave/ChangeLog
diffstat 2 files changed, 44 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Mon Nov 24 21:24:37 2003 +0000
+++ b/liboctave/Array.cc	Mon Nov 24 23:59:12 2003 +0000
@@ -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);
 
--- a/liboctave/ChangeLog	Mon Nov 24 21:24:37 2003 +0000
+++ b/liboctave/ChangeLog	Mon Nov 24 23:59:12 2003 +0000
@@ -1,5 +1,7 @@
 2003-11-24  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* 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  <jwe@bevo.che.wisc.edu>