bugGNU Octave - Bugs: bug #42408, Matlab incompatible results for...

 
 

bug #42408: Matlab incompatible results for isequal() with character/double comparisions

Submitted by:  Kai Torben Ohlhus <siko1056>
Submitted on:  Fri 23 May 2014 02:19:33 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Kai T. Ohlhus Open/Closed:  Closed
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Wed 28 May 2014 03:26:01 PM UTC, comment #9: 

Sorry I missed that.  I added your tests in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/ff613b6a7b6f).  I did a few tweaks for Octave coding conventions.  We prefer the double quote to the single quote for example.  I also added tests for recursive structures and cells since that is an important part of isequal.

While testing I found that isequal doesn't work with java objects.  I'll file a separate bug report about that.

Rik <rik5>
Project Administrator
Wed 28 May 2014 06:39:37 AM UTC, comment #8: 

At the bottom of this page "Attached Files" I can see the file I uploaded:

https://savannah.gnu.org/bugs/download.php?file_id=31423

Did I set wrong visibility attributes or alike?

Kai Torben Ohlhus <siko1056>
Project Member
Wed 28 May 2014 01:36:01 AM UTC, comment #7: 

"All previous test cases are contained in my changeset"

Did you upload a changeset?  I don't see anything attached to the bug report.

Rik <rik5>
Project Administrator
Tue 27 May 2014 11:03:08 PM UTC, comment #6: 

Thank you for the fix Rik. Was it possible to add some of my test cases to isequal.m in the folder above? This might avoid someone to break this desired behavior with another change. All previous test cases are contained in my changeset and all my tests are fulfilled.

Regards,
Kai

Kai Torben Ohlhus <siko1056>
Project Member
Tue 27 May 2014 09:17:21 PM UTC, comment #5: 

I made Octave Matlab compatible with respect to character/numeric comparisons in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/1f170b211be3).  This is on the development branch so you will need to get the file _isequal_.m from Mercurial if you need the fix sooner than the 4.2 release.

Rik <rik5>
Project Administrator
Sun 25 May 2014 09:31:23 PM UTC, comment #4: 

Here the results for MATLAB 2013b again:

 >> x = single (83);
y = single (84);
isequal ([x y], 'ST')
ans =
     1
>> x = complex (83, 0)
x =
  83.0000 + 0.0000i
>> isequal (x, 'S')
ans =
     1
>> isequal (uint8 (83), 'S')
ans =
     1

Kai Torben Ohlhus <siko1056>
Project Member
Sun 25 May 2014 05:39:07 PM UTC, comment #3: 

I checked in a change that matches the return sizes Matlab uses for uncommon inputs (like 0x1, 1x0, 1x1 (but empty)) (http://hg.savannah.gnu.org/hgweb/octave/rev/a5286fb173cd).  That takes care of the first problem which is the worst.

The other two comparisons are because Matlab seems to internally promote characters to a numeric class.  Could you try running these experiments?

 

x = single (83);
y = single (84);
isequal ([x y], 'ST')
x = complex (83, 0)
isequal (x, 'S')
isequal (uint8 (83), 'S')

Rik <rik5>
Project Administrator
Sun 25 May 2014 12:37:42 PM UTC, comment #2: 

Hi Rik,

I think you are right, here the output from MATLAB 2013b:

 >> x = sparse ([])
 x =
    All zero sparse: 0-by-0

 >> f_x = find (x)
 f_x =
      []

 >> size (f_x)
 ans =
      0     0

 >> x = ones (0,100,2)
 x =
    Empty array: 0-by-100-by-2

 >> f_x = find (x)
 f_x =
    Empty matrix: 0-by-1

 >> size (f_x)
 ans =
      0     1

What do you suggest to overcome this issue?

Best,
Kai

Kai Torben Ohlhus <siko1056>
Project Member
Fri 23 May 2014 03:48:33 PM UTC, comment #1: 

Confirmed.

Since you have access to Matlab, could you try the following?

x = sparse ([])
f_x = find (x)
size (f_x)
x = ones (0,100,2);
f_x = find (x)
size (f_x)

The problem seems to be that Octave returns a [](0x1) matrix from find() when the input is empty rather than a [](0x0) matrix.

Rik <rik5>
Project Administrator
Fri 23 May 2014 02:19:33 PM UTC, original submission:  

Hello,

I encountered incorrect results for the equality comparison of empty sparse matrices, which results in a hard error and the comparison for alphanumerical values.

In Octave:
octave:2> isequal (sparse([]),[])
error: _isequal_: mx_el_eq: nonconformant arguments (op1 is 0x1, op2 is 0x0)
error: evaluating argument list element number 1
error: called from:
error:   /usr/local/share/octave/4.1.0+/m/general/private/__isequal__.m at line 161, column 11
error:   /usr/local/share/octave/4.1.0+/m/general/isequal.m at line 31, column 10
octave:2> isequal (83, char(83))
ans = 0
octave:3> isequal (83, 'S')
ans = 0
-verbatim-

In MATLAB:

>> isequal (sparse([]),[])
ans = 1
>> isequal (83, char(83))
ans = 1
>> isequal (83, 'S')
ans = 1

I will submit a patch with more test cases shortly.

Regards,
Kai

Kai Torben Ohlhus <siko1056>
Project Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #31423:  isequal_bug_42408.diff added by siko1056 (7KiB - text/x-patch)

 

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 siko1056 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-05-27 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2014-05-25 rik5 SummaryIncorrect results of isequal() with empty sparse matrices and alphanumerical value comparision. => Matlab incompatible results for isequal() with character/double comparisions
    2014-05-25 rik5 Item GroupIncorrect Result => Matlab Compatibility
    2014-05-23 rik5 StatusNone => Confirmed
    2014-05-23 siko1056 Attached File- => Added isequal_bug_42408.diff, #31423

    Back to the top


    Powered by Savane 3.5