From help-octave-request at bevo dot che dot wisc dot edu Thu Feb 5 12:02:40 2004 Subject: Re: subscripted assignment dimension mismatch (NDArray) From: Taku J SATO To: "John W. Eaton" Cc: Octave_post Date: Fri, 6 Feb 2004 03:01:27 +0900 hi, thank you very much for the patch; it works very nicely now. btw, with octave-2.1.53, we cannot use the third index in the following case: ----- octave:1> test=zeros(4,4,1) test = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 octave:2> test(1,1,1) error: index exceeds N-d array dimensions ----- to avoid this difficulty, i use: ------ octave:2> test=reshape(zeros(4,4,1),4,4,1) test = ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 octave:3> test(1,1,1) ans = 0 ----- is this behavior what octave is supposed to do? (i presently do not have access to matlab, so i am not sure what matlab would do...) all the best, taku On Feb 5, 2004, at 3:40, John W. Eaton wrote: > On 4-Feb-2004, Taku J SATO wrote: > > | thanks for your quick reply. perhaps, my example was not good. > | what i want to do is as follows: > | > | ----- > | octave:1> test = zeros(4,4,2) > | octave:2> test2 = [1,2]' > | octave:3> test(1:2,1,1) = test2 > | error: subscripted assignment dimension mismatch > | error: assignment failed, or no method for `matrix = matrix' > | error: evaluating assignment expression near line 3, column 15 > | ------ > | > | actually, i am playing with much bigger arrays (such as 5D array > | assigned by 2D matrix.) the above is the simplest case i could > | reproduce the problem. > | > | (i am presently writing a program which produces all the irreducible > | representations of the k-groups of the crystallographic space groups. > | this program seems running on octave-2.1.52 but fails under > 2.1.53...) > | > | all the best, > | taku > > Please try the following patch. > > Thanks, > > jwe > > > 2004-02-04 John W. Eaton > > * Array.cc (Array::assignN): Simplify dimension check by > comparing rhs_dims and frozen_len sans trailing singletons. > > > Index: liboctave/Array.cc > =================================================================== > RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v > retrieving revision 1.86 > diff -c -r1.86 Array.cc > *** liboctave/Array.cc 23 Jan 2004 03:09:59 -0000 1.86 > --- liboctave/Array.cc 4 Feb 2004 18:26:11 -0000 > *************** > *** 2746,2781 **** > { > // RHS is matrix or higher dimension. > > - bool dim_ok = true; > - > - int jj = 0; > - > // Check that RHS dimensions are the same length as the > ! // corresponding LHS dimensions. > ! > ! int rhs_dims_len = rhs_dims.length (); > > ! for (int j = 0; j < idx_is_colon.length (); j++) > ! { > ! if (jj < rhs_dims.length () && rhs_dims(jj) == 1) > ! jj++; > ! else if (idx_is_colon(j)) > ! { > ! if (jj > rhs_dims_len || rhs_dims(jj) < lhs_dims(j)) > ! { > ! dim_ok = false; > ! > ! break; > ! } > ! > ! jj++; > ! } > ! } > > ! if (jj != rhs_dims_len) > ! dim_ok = false; > > ! if (! dim_ok) > (*current_liboctave_error_handler) > ("subscripted assignment dimension mismatch"); > else > --- 2746,2761 ---- > { > // RHS is matrix or higher dimension. > > // Check that RHS dimensions are the same length as the > ! // corresponding LHS index dimensions. > > ! dim_vector t_rhs_dims = rhs_dims; > ! t_rhs_dims.chop_trailing_singletons (); > > ! dim_vector t_frozen_len = frozen_len; > ! t_frozen_len.chop_trailing_singletons (); > > ! if (t_rhs_dims != t_frozen_len) > (*current_liboctave_error_handler) > ("subscripted assignment dimension mismatch"); > else > > -- Taku J Sato ------------------------------------------------------------- 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 -------------------------------------------------------------