[Changeset] Re: Indexing where all entries are false

David Bateman David.Bateman at motorola.com
Tue May 13 10:47:07 CDT 2008


Richard Bovey wrote:
> The result of indexing a vector with logicals has changed from 3.0.0 to
> 3.0.1. I believe that the 3.0.1 behaviour maybe considered incorrect as it
> is inconsistent with Matlab, while 3.0.0 was consistent with Matlab.
>
> In 3.0.1 if all the entries in the index are false a matrix with size 0x0 is
> returned, while 3.0.1 returns 1x0 or 0x1 depending on the shape of the input
> vector.
>
> I'm using Windows XP.
>
>   
The cause seems to be the change

http://velveeta.che.wisc.edu/cgi-bin/hgwebdir.cgi/octave/diff/85da2ab0c6fd/liboctave/idx-vector.cc

where if the length of an index vector is zero when created from an
boolNDArray then the dimensions of the idnex vector are incorrectly set
to dim_vector(0,0). The changelog entry for this change is

2008-03-07  John W. Eaton  <jwe at octave.org>

        * idx-vector.cc (IDX_VEC_REP::idx_vector_rep (bool),
        IDX_VEC_REP::idx_vector_rep (const boolNDArray&)):
        Simply perform the equivalent of "find" on the bool argument here,
        set one_zero to 0 and orig_dims to size of resulting index vector.
        (IDX_VEC_REP::freeze): Don't call maybe_convert_one_zero_to_idx
here.

The changest log is marked as "logical indexing compatibility fixes
<http://velveeta.che.wisc.edu/cgi-bin/hgwebdir.cgi/octave/rev/5cd053b8d9cd>"
and so we'd have to be careful not to just back out this change but also
address the original issue. The original problem is discuss here

http://www.nabble.com/Incompatibility-with-matlab-logical-indexing-to15908186.html

We therefore also need to check the following

>> a = [1 2; 3 4]

a =

     1     2
     3     4

>> a([1, 1] == 1)

ans =

     1     3

>> a([1, 1] == 0)

ans =

   Empty matrix: 1-by-0

>> a([1; 1] == 0)

ans =

   Empty matrix: 0-by-1

which is the output from MatlabR2007b. I suppose the fix is then the
attached which seems to address both your problem, the above and the
original problem.

Regards
David

-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch8080
Url: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080513/db01b3d3/attachment-0001.ksh 


More information about the Bug-octave mailing list