[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: subscripted assignment dimension mismatch (NDArray)
From: |
John W. Eaton |
Subject: |
Re: subscripted assignment dimension mismatch (NDArray) |
Date: |
Wed, 4 Feb 2004 12:40:36 -0600 |
On 4-Feb-2004, Taku J SATO <address@hidden> 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 <address@hidden>
* Array.cc (Array<T>::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
-------------------------------------------------------------
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
-------------------------------------------------------------