« Return to Thread: Indexing where all entries are false

[Changeset] Re: Indexing where all entries are false

by David Bateman :: Rate this Message:

Reply to Author | View in Thread

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

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


# HG changeset patch
# User David Bateman <dbateman@...>
# Date 1210693535 -7200
# Node ID e4affe5a2f978db78f6efbd705a79304b3bdc3d9
# Parent  9210dcd13292ed5f686ea2a926aa77bda7d0fcde
all false logical indexing fix

diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,9 @@ 2008-05-06  David Bateman  <dbateman@fre
+2008-05-13  John W. Eaton  <jwe@...>
+
+ * idx-vector.cc (IDX_VEC_REP::idx_vector_rep (const boolNDArray&)):
+ If len is zero size the index vector in the same manner as if len
+ is not zero.
+
 2008-05-06  David Bateman  <dbateman@...>
 
  * Array.cc (Array<T> Array<T>::transpose () const): Modify for tiled
diff --git a/liboctave/idx-vector.cc b/liboctave/idx-vector.cc
--- a/liboctave/idx-vector.cc
+++ b/liboctave/idx-vector.cc
@@ -270,11 +270,13 @@ IDX_VEC_REP::idx_vector_rep (const boolN
     range(0), initialized (0), frozen (0),
     colon_equiv_checked (0), colon_equiv (0), orig_dims ()
 {
+  dim_vector dv = bnda.dims ();
+
+  orig_dims = ((dv.length () == 2 && dv(0) == 1)
+       ? dim_vector (1, len) : orig_dims = dim_vector (len, 1));
+
   if (len == 0)
-    {
-      orig_dims = dim_vector (0, 0);
-      initialized = 1;
-    }
+    initialized = 1;
   else
     {
       data = new octave_idx_type [len];
@@ -284,11 +286,6 @@ IDX_VEC_REP::idx_vector_rep (const boolN
       for (octave_idx_type i = 0, k = 0; i < ntot && k < len; i++)
  if (bnda.elem (i))
   data[k++] = i;
-
-      dim_vector dv = bnda.dims ();
-
-      orig_dims = ((dv.length () == 2 && dv(0) == 1)
-   ? dim_vector (1, len) : orig_dims = dim_vector (len, 1));
 
       init_state ();
     }

_______________________________________________
Bug-octave mailing list
Bug-octave@...
https://www.cae.wisc.edu/mailman/listinfo/bug-octave

 « Return to Thread: Indexing where all entries are false

LightInTheBox - Buy quality products at wholesale price