help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Inconsistent behaviour of (:)


From: John W. Eaton
Subject: Inconsistent behaviour of (:)
Date: Tue, 22 Feb 2005 10:31:44 -0500

On 22-Feb-2005, Thomas Weber <address@hidden> wrote:

| I just noticed something which I am not sure about wether it's a bug or
| not:
| 
| octave:1> e1 = [1,0]
| e1 =
| 
|   1  0
| 
| octave:2> acos(e1)(:)
| ans =
| 
|   0.00000  1.57080
| 
| octave:3> cos(e1)(:)
| ans =
| 
|   0.54030
|   1.00000
| 
| Why does the acos command return a row-vector? 
| b = acos(e1);
| b(:)
| returns a column vector (as I expected).
| 
| Am I doing something wrong?

It looks like a bug to me.  Please try the following patch.

Thanks,

jwe


src/ChangeLog:

2005-02-22  John W. Eaton  <address@hidden>

        * ov-mapper.cc (octave_mapper::subsref): Return retval after
        calling next_subsref.

        * ov-mapper.cc (octave_builtin::subsref): If nargout is 0 and we
        have additional indexing to perform, set it to 1 before calling
        do_multi_index_op.


Index: src/ov-mapper.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-mapper.cc,v
retrieving revision 1.22.2.1
diff -u -r1.22.2.1 ov-mapper.cc
--- src/ov-mapper.cc    27 Jan 2005 16:56:19 -0000      1.22.2.1
+++ src/ov-mapper.cc    22 Feb 2005 15:22:38 -0000
@@ -250,7 +250,11 @@
   switch (type[0])
     {
     case '(':
-      retval = do_multi_index_op (nargout, idx.front ());
+      {
+       int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
+
+       retval = do_multi_index_op (tmp_nargout, idx.front ());
+      }
       break;
 
     case '{':
@@ -265,14 +269,14 @@
       panic_impossible ();
     }
 
-  return retval;
-
   // XXX FIXME XXX -- perhaps there should be an
   // octave_value_list::next_subsref member function?  See also
   // and octave_builtin::subsref.
 
   if (idx.size () > 1)
     retval = retval(0).next_subsref (nargout, type, idx);
+
+  return retval;
 }
 
 octave_value_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
-------------------------------------------------------------



reply via email to

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