[Changeset] Re: Indexing where all entries are false

John W. Eaton jwe at bevo.che.wisc.edu
Tue May 13 12:20:11 CDT 2008


On 13-May-2008, David Bateman wrote:

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

I applied this patch, but replaced my name with yours in the ChangeLog
entry.

Thanks,

jwe


More information about the Bug-octave mailing list