[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: empty ranges are matrices ?

**From**: |
Jean-Francois Cardoso |

**Subject**: |
Re: empty ranges are matrices ? |

**Date**: |
Tue, 29 Mar 2005 21:03:17 +0200 |

On Mar 29, John W. Eaton wrote:
>* On 29-Mar-2005, Jean-Francois Cardoso <address@hidden> wrote:*
>* *
>* | Is it expected behavior that empty ranges have type "matrix" and not*
>* | "range"?*
>* | *
>* | octave> typeinfo(0:1)*
>* | ans = range*
>* | octave> typeinfo(1:0)*
>* | ans = matrix*
>* | octave> size(1:0)*
>* | ans =*
>* | *
>* | 1 0*
>* | *
>* | octave> version*
>* | ans = 2.1.67*
>* *
>* Yes, the same as it is expected that a range with a single element is*
>* converted to a scalar object. Is this a problem? How?*
It is not a problem that I cannot work around, of course. But it may
appear counterintuitive: I was disturbed at first that an empty object
cannot be "stacked" freely, in the sense that:
octave> r = 1:-1 ; s = [ r 1 ]
s = 1
octave> r = 1:-1 ; s = [ r ; 1 ]
error: number of columns must match (1 != 0)
while I can do
octave> vide = zeros(0) ;
octave> [ vide 1 ] ;
octave> [ vide ; 1 ] ;
octave>
but I now understand that an empty range should be more naturally
represented as [](1x0) than as [](0x0). Hence the above error.
But we may have a more serious problem here:
octave> zeros(0)
ans = [](0x0)
octave> zeros([])
warning: zeros (A): use zeros (size (A)) instead
ans = 0
octave>
Octave does produce a warning, but nothing more.
Do we really want zeros([]) to return a SCALAR rather than an empty
object?
Best regards, JF
-------------------------------------------------------------
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
-------------------------------------------------------------