help-octave
[Top][All Lists]
Advanced

[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: Thu, 5 Feb 2004 12:24:40 -0600

On  6-Feb-2004, Taku J SATO <address@hidden> wrote:

| 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
| -----

Please try the following patch.

| 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

I don't think this should work to increase the number of dimensions
from 2 to 3.  Since the trailing dimension is a singleton, I think it
should be removed.

The current CVS sources have some additional fixes for N-d array
indexing and indexed assignments.  I'm also hoping to make a new
snapshot later this week.

jwe


2004-02-05  John W. Eaton  <address@hidden>

        * Array.cc (Array<T>::index): Remove trailing singletons in
        ra_idx, but leave at least ndims elements.


Index: liboctave/Array.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/liboctave/Array.cc,v
retrieving revision 1.89
diff -u -r1.89 Array.cc
--- liboctave/Array.cc  5 Feb 2004 18:04:54 -0000       1.89
+++ liboctave/Array.cc  5 Feb 2004 18:22:11 -0000
@@ -2025,6 +2025,21 @@
 
   int n_dims = dimensions.length ();
 
+  // Remove trailing singletons in ra_idx, but leave at least ndims
+  // elements.
+
+  int ra_idx_len = ra_idx.length ();
+
+  while (ra_idx_len > n_dims)
+    {
+      if (ra_idx(ra_idx_len-1) == 1)
+       ra_idx_len--;
+      else
+       break;
+    }
+
+  ra_idx.resize (ra_idx_len);
+
   if (n_dims < ra_idx.length ())
     {
       (*current_liboctave_error_handler)



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]