bugGNU Octave - Bugs: bug #44071, ismember fails with unsorted...

 
 

bug #44071: ismember fails with unsorted complex set

Submitter:  None
Submitted:  Fri 23 Jan 2015 01:33:28 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Henry Shu Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.8.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 26 Jan 2015 11:35:19 PM UTC, comment #4: 

There was a cut and paste error in Array-C.cc where instead of comparing x and y, x and x were compared.


diff -r e68267373191 liboctave/array/Array-C.cc
--- a/liboctave/array/Array-C.cc        Sat Jan 24 22:27:12 2015 -0800
+++ b/liboctave/array/Array-C.cc        Mon Jan 26 15:31:14 2015 -0800
@@ -46,8 +46,8 @@ nan_ascending_compare (const Complex& x,
 {
   return (xisnan (y)
           ? ! xisnan (x)
-          : ((std::abs (x) < std::abs (x))
-             || ((std::abs (x) == std::abs (x)) && (arg (x) < arg (x)))));
+          : ((std::abs (x) < std::abs (y))
+             || ((std::abs (x) == std::abs (y)) && (arg (x) < arg (y)))));
 }

 static bool
@@ -55,8 +55,8 @@ nan_descending_compare (const Complex& x
 {
   return (xisnan (x)
           ? ! xisnan (y)
-          : ((std::abs (x) > std::abs (x))
-             || ((std::abs (x) == std::abs (x)) && (arg (x) > arg (x)))));
+          : ((std::abs (x) > std::abs (y))
+             || ((std::abs (x) == std::abs (y)) && (arg (x) > arg (y)))));
 }


This has been fixed on the development branch in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/884e0c55d92c).  The reporter will need to build from Mercurial sources in order to see the fix.

Rik <rik5>
Group administrator
Fri 23 Jan 2015 09:52:23 AM UTC, comment #3: 

Matlab r2015a prerelease on Windows:

Matlab cannot load the mat file directly:

>> load ismember_bug.mat
Error using load
Unable to read MAT-file c:\tmp\ismember_bug.mat. Not a binary MAT-file. Try LOAD -ASCII to read as text.


...so I had to first load the .mat file in Octave and write it as -v7 .mat file.

(@Carlo: I didn't see a variable "ii" in Octave.)

Anyway, Matlab gives:

>> whos
  Name        Size            Bytes  Class     Attributes

  A           1x1                 8  double
  s         299x1              4784  double    complex

>> disp (any (s == A))
     1

>> disp (ismember (A, s))
     1

>> disp (ismember (A, real (s)))
     1

>> disp(ismember(complex(0,0), real (s)))
     1


It could be that Matlab casts A into a complex type before attempting ismember() s.s.
IMO that seems the logical thing to do.

(OS -> Any; status -> confirmed)

Philip Nienhuis <philipnienhuis>
Group Member
Fri 23 Jan 2015 08:11:27 AM UTC, comment #2: 

the values stored in the attached file
are complex.


>> load ismember_bug.mat
>> whos
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        A           1x1                          8  double
        ii          1x1                          8  double
   c    s         299x1                       4784  double

Total is 301 elements using 4800 bytes

>>


If using only the real part of 's' ismember works as you
would expect:


>> disp(ismember(A, real (s)));
1


Checking for a complex zero, i.e. 0+i0 also works:


>> disp(ismember(complex(0,0), real (s)));
 1


I don't know whether it would be correct
for ismember to report true when looking for
a zero of type double in an array of type
complex.

Does anyone know what Matlab does in this case?



Carlo de Falco <cdf>
Group Member
Fri 23 Jan 2015 04:49:20 AM UTC, comment #1: 

Thanks for your bug report. The failure occurs because the column vector s is not sorted and because issorted(s) returns true. The ismember function relies on these functions to behave consistently for the provided set. So the fix maybe should resolve issorted for complex inputs.


load ismember_bug.dat
issorted (s)     ## -> 1
s2 = sort (s);
isequal (s, s2)  ## -> 0
ismember (A, s)  ## -> 0
ismember (A, s2) ## -> 1


Mike Miller <mtmiller>
Group Member
Fri 23 Jan 2015 01:33:28 AM UTC, original submission:  

Please load ismember_bug.mat attached

A is a scalar double of value 0.
s is a column vector of 299 double values containing at least one 0.
However, ismember failed to recognize the membership of A in s.


load("ismember_bug.mat");
disp(any(s == A));  # Displays 1
disp(ismember(A, s));  # Displays 0, hence a bug


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32901:  ismember_bug.mat added by None (5KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by cdf (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-01-26 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2015-01-23 philipnienhuis StatusNeed Info Confirmed
        Operating SystemGNU/Linux Any
    2015-01-23 cdf StatusConfirmed Need Info
    2015-01-23 mtmiller Item GroupNone Incorrect Result
        StatusNone Confirmed
        Summaryismember fails to recognize set membership ismember fails with unsorted complex set
    2015-01-23 None Attached File- Added ismember_bug.mat, #32901

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code