help-octave
[Top][All Lists]

## product of empty vectors

 From: John W. Eaton Subject: product of empty vectors Date: Sat, 24 May 2003 21:40:09 -0500

```On 23-May-2003, I wrote:

| On 23-May-2003, Douglas Harder <address@hidden> wrote:
|
| | Octave's handling of empty matrices is a little odd:
| |
| | >> a = 1:2
| | a =
| |   1  2
| | >> a(1:0)
| | ans = []
| | >> ans * ans'   % this should be 0
| | ans = []
| | >> ans + 3
| | ans = []
|
| The only real problem here is that Octave interprets 1:0 as a 0x0
| empty matrix instead of a 1x0 empty matrix.  Should we change that?

OK, after a bit of thought, I think we should (if you disagree, please
speak up).  Here is a patch.

Thanks,

jwe

* ov-range.cc (try_narrowing_conversion): Convert to [](1x0)
instead of [](0x0) if range is empty.

Index: src/ov-range.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-range.cc,v
retrieving revision 1.28
diff -u -r1.28 ov-range.cc
--- src/ov-range.cc     23 Feb 2003 02:16:53 -0000      1.28
+++ src/ov-range.cc     25 May 2003 02:35:46 -0000
@@ -71,7 +71,7 @@
break;

case 0:
-      retval = new octave_matrix (Matrix ());
+      retval = new octave_matrix (Matrix (1, 0));
break;

default:

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

```