|
Assignment to subarray of ND array fails: msg#00003gnu.octave.bugs
On 31-Mar-2005, Quentin Spencer <qspencer@xxxxxxxx> wrote: | The following commands all work in Matlab 7, and fail in Octave 2.1.69: | | octave:1> a(:,:,1)=ones(2); | octave:2> b(:,1,:)=ones(2); | error: A(IDX-LIST) = X: X must be a scalar or size of X must equal | number of elements indexed by IDX-LIST | error: assignment failed, or no method for `matrix = matrix' | error: evaluating assignment expression near line 2, column 9 | octave:2> c(1,:,:)=ones(2); | error: A(IDX-LIST) = X: X must be a scalar or size of X must equal | number of elements indexed by IDX-LIST | error: assignment failed, or no method for `matrix = matrix' | error: evaluating assignment expression near line 2, column 9 Please try the following patch. Thanks, jwe 2005-04-01 John W. Eaton <jwe@xxxxxxxxxx> * Array.cc (assignN): For A(IDX-LIST) = RHS with A previously undefined, correctly match colons in IDX-LIST with RHS dimensions when resizing A. When performing the assignment, just check that the number of elements in RHS matches the number of elements indexed by IDX-LIST. Index: liboctave/Array.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v retrieving revision 1.124.2.2 diff -u -r1.124.2.2 Array.cc --- liboctave/Array.cc 26 Jan 2005 22:10:11 -0000 1.124.2.2 +++ liboctave/Array.cc 1 Apr 2005 18:00:18 -0000 @@ -2996,23 +2996,37 @@ dim_vector new_dims; new_dims.resize (n_idx); - for (int i = 0; i < n_idx; i++) + if (orig_empty) { - if (orig_empty) + int k = 0; + for (int i = 0; i < n_idx; i++) { // If index is a colon, resizing to RHS dimensions is // allowed because we started out empty. - new_dims(i) - = (i < rhs_dims.length () && idx(i).is_colon ()) - ? rhs_dims(i) : idx(i).max () + 1; + if (idx(i).is_colon ()) + { + if (k < rhs_dims.length ()) + new_dims(i) = rhs_dims(k++); + else + { + (*current_liboctave_error_handler) + ("A(IDX-LIST) = RHS: A previously undefined and more colons in IDX-LIST than dimensions for RHS"); + return retval; + } + } + else + new_dims(i) = idx(i).max () + 1; } - else + } + else + { + for (int i = 0; i < n_idx; i++) { // We didn't start out with all zero dimensions, so if // index is a colon, it refers to the current LHS // dimension. Otherwise, it is OK to enlarge to a - // dimension given by the largest index, but if that + // dimension given by the largest index, but if that // index is a colon the new dimension is singleton. if (i < lhs_dims_len @@ -3088,33 +3102,9 @@ { // RHS is matrix or higher dimension. - // Check that non-singleton RHS dimensions conform to - // non-singleton LHS index dimensions. - - dim_vector t_rhs_dims = rhs_dims.squeeze (); - dim_vector t_frozen_len = frozen_len.squeeze (); - - // If after sqeezing out singleton dimensions, RHS is - // vector and LHS is vector, force them to have the same - // orientation so that operations like - // - // a = zeros (3, 3, 3); - // a(1:3,1,1) = [1,2,3]; - // - // will work. - - if (t_rhs_dims.length () == 2 && t_frozen_len.length () == 2 - && ((t_rhs_dims.elem(1) == 1 - && t_frozen_len.elem(0) == 1) - || (t_rhs_dims.elem(0) == 1 - && t_frozen_len.elem(1) == 1))) - { - int t0 = t_rhs_dims.elem(0); - t_rhs_dims.elem(0) = t_rhs_dims.elem(1); - t_rhs_dims.elem(1) = t0; - } + int n = Array<LT>::get_size (frozen_len); - if (t_rhs_dims != t_frozen_len) + if (n != rhs.numel ()) { (*current_liboctave_error_handler) ("A(IDX-LIST) = X: X must be a scalar or size of X must equal number of elements indexed by IDX-LIST"); ------------------------------------------------------------- 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 ------------------------------------------------------------- |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: bug in imshow and one more question about types float32: 00003, John W. Eaton |
|---|---|
| Next by Date: | Re: bug in imshow with all negative values: 00003, Stefan van der Walt |
| Previous by Thread: | Re: bug in imshow and one more question about types float32i: 00003, Etienne de Foras |
| Next by Thread: | function cumsum aborts octave: 00003, Jiří Poláček |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |