[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Create a logical array of 0
From: |
David Bateman |
Subject: |
Re: Create a logical array of 0 |
Date: |
Fri, 3 Sep 2004 16:48:03 +0200 |
User-agent: |
Mutt/1.4.1i |
Ok, this is a bug I introduced in the week before release. The problem
is here.
x = a * ones(idx, class(a))
as with the previously zeros(m,n,"logical") issue, ones(m,n,"logical")
isn't defined!!! A workaround for your case is repmat([false, false],10,5);
I don't like any of the real solutions though... Replacing the above with
x = a * ones(idx)
won't work for integer types..
_conv = eval(["@",class(a),";"]);
x = _conv (double(a) * ones(idx))
is just too ugly and in any case creates a double matrix first and so uses
too much memory and isn't guarenteed to work on 64-bit types.. And
I can't easily special case this line since I'd have to do something like
cls = class (a);
if (cls == "double" || cls == "int8" || cls == "int16" || cls = "int32"
|| cls == "int64" || cls == "uint8" || cls == "uint16"
|| cls == "uint32" || cls == "uint64")
x = a * ones(idx, class(a))
else
cidx = cell (1, length (idx));
for i=1:length(idx)
cidx{i} = ones (1,idx(i));
endfor
x = a (cidx{:});
endif
but the test is long and it seems indexed booleans return a matrix!!
(i.e false(1,[1,1]) gives the matrix [0,0] and not [false,false])
This is in fact represents a problem with repmat for all logical values,
as it will always return a matrix...
The last version is the only real solution. But if we don't want to implicit
convert the boolean matrix to a matrix, then indexed boolean values need
to return booleans and the concatenation [false,false] also needs to return
boolean, which they don't at the moment..
D.
According to Josep Monés i Teixidor <address@hidden> (on 09/03/04):
> On dv, 2004-09-03 at 15:23, Josep Monés i Teixidor wrote:
> > If tried zeros(m,n,"logical") but didn't work for logical.
> >
>
> Neither did repmat([false],m,n).
>
> BTW, "repmat(false,m,n)" fails with an error (I'm not sure if it should
> but I think I'd got be good not to):
>
> octave:15> repmat(false,10,10)
> error: invalid data type specified
> error: unable to find matching native data type for logical
> error: evaluating binary operator `*' near line 58, column 13
> error: evaluating assignment expression near line 58, column 9
> error: evaluating if command near line 55, column 5
> error: evaluating if command near line 54, column 3
> error: called from `repmat' in file
> `/home/josep/binaries/octave/share/octave/2.1.58/m/general/repmat.m'
>
>
> --
> Josep Monés i Teixidor
> Clau GnuPG: gpg --recv-keys 80E85CC4
--
David Bateman address@hidden
Motorola CRM +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
-------------------------------------------------------------
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
-------------------------------------------------------------
RE: Create a logical array of 0, Randy Gober, 2004/09/03
Re: Create a logical array of 0, David Bateman, 2004/09/03