From bug-octave-request at bevo dot che dot wisc dot edu Thu Jan 22 21:07:28 2004 Subject: indexing error From: "John W. Eaton" To: Paul Kienzle Cc: bug-octave at bevo dot che dot wisc dot edu Date: Thu, 22 Jan 2004 21:06:24 -0600 On 11-Dec-2003, Paul Kienzle wrote: | octave-2.1.52, Debian linux package | | octave:18> x=eye(2); x([1,1,1,1,1])=1 | error: A(I) = X: X must be a scalar or a matrix with the same size as I | error: assignment failed, or no method for `matrix = scalar' | error: evaluating assignment expression near line 18, column 25 Please try the following patch. Thanks, jwe 2004-01-22 John W. Eaton * Array.cc (Array::assign2, Array::assignN): For X(I) = RHS, don't restrict I to fewer elements than X. * Array.cc (Array::assign2): Simplify indexing for X(I) = RHS case. Index: liboctave/Array.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v retrieving revision 1.85 diff -u -r1.85 Array.cc --- liboctave/Array.cc 22 Jan 2004 19:30:54 -0000 1.85 +++ liboctave/Array.cc 23 Jan 2004 02:59:54 -0000 at @ -2496,16 +2496,14 @@ } } } - else if (rhs_nr == 1 && rhs_nc == 1 && len <= lhs_nr * lhs_nc) + else if (rhs_nr == 1 && rhs_nc == 1) { RT scalar = rhs.elem (0, 0); for (int i = 0; i < len; i++) { int ii = idx_i.elem (i); - int fr = ii % lhs_nr; - int fc = (ii - fr) / lhs_nr; - lhs.elem (fr, fc) = scalar; + lhs.elem (ii) = scalar; } } else at @ -2642,7 +2640,7 @@ lhs.elem (ii) = rhs.elem (i); } } - else if (rhs_is_scalar && len <= lhs_len) + else if (rhs_is_scalar) { RT scalar = rhs.elem (0); ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------