bugGNU Octave - Bugs: bug #47865, cplxpair(array,tol) uses wrong...


bug #47865: cplxpair(array,tol) uses wrong units for tol

Submitted by:  None
Submitted on:  Fri 06 May 2016 12:33:22 PM UTC  
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Gene Petilli Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  dev
Operating System:  GNU/Linux

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)

Tue 29 Aug 2017 10:53:11 PM UTC, comment #8: 

This looks good now.  Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Tue 29 Aug 2017 09:14:06 PM UTC, comment #7: 

I just pushed the patch from bug #50124.  Does that address any of the issues in this report?

I just stepped through all the cases in the diary file that was posted here and the results from Octave seem to agree now.

Can this report be closed?

John W. Eaton <jwe>
Project Administrator
Fri 13 May 2016 04:21:35 PM UTC, comment #6: 

Thanks for the upload.  I'll try and look at the results this weekend.

Rik <rik5>
Project Administrator
Wed 11 May 2016 09:08:38 PM UTC, comment #5: 

I changed the Item Type to Matlab Compatibility and marked the bug as confirmed.

Could you run the examples in comment #3 and report the results back?  If you don't want to do copy/paste then you can use

diary on
% enter code from comment #3
diary off

and then uplad the file named "diary" to this bug report.

Rik <rik5>
Project Administrator
Wed 11 May 2016 08:16:53 PM UTC, comment #4: 


I checked Matlab and it orders the matrix based on ABS(a) and the TOL is absolute (not relative) between the elements of ABS(a) but the real(a) needs to be same sign and the imag(a) must be inverse sign.

Do you need anything else to move from "need info" to confirmed and to get assigned?

Gene <gpetilli>
Tue 10 May 2016 04:18:10 AM UTC, comment #3: 

I think we may be able to piece together what Matlab is doing.  From the help statement within Matlab they say they are using a relative tolerance.  The calculation for relative error is

(x - y) / min (x, y)

From the online documentation, they mention that the tolerance is relative to abs (A(i)).

This suggests that they are calculating

(abs (x) - abs (y) / (min (abs (x), abs (y)) < TOL

Of course, Matlab might be doing the same relative calculation separately for the real part and for the imaginary part.  Can you run the following and report back what Matlab does?

z = [-4 + 5i; 4.5 - 6i];
z = cplxsort (z)           % Default tolerance should fail
z = cplxsort (z, .15)
z = cplxsort (z, .18)
% If neither of these works, can you find what tolerance does allow this to succeed?

Another check is to see whether there are separate tests for the real and imaginary parts.  If there aren't then two numbers which have the same magnitude will compare as equal.

z = [ -1 + 2i; 2 - i ];
cplxsort (z)

Rik <rik5>
Project Administrator
Mon 09 May 2016 12:37:54 PM UTC, comment #2: 

in matlab help cmpxpair says:

    Y = cplxpair(X,TOL) uses a relative tolerance TOL to perform the
    comparisons needed for the complex conjugate pairings. TOL must
    be a scalar such that 0<=TOL<1. The default is TOL = 100*EPS.

I take this to mean that the default for TOL is 100*EPS, not 100 (which is later multiplied by EPS).  If I set TOL=0.001 it should pair complex numbers where both the real is within +/-0.001 and the negative of the imaginary is within +/-0.001.  This is consistent with the results I get from your test cases

>> cplxpair (z2, -0.1)

Error using cplxpair (line 41)
Relative tolerance TOL must be a scalar such that 0<=TOL<1.

>> cplxpair (z2, 0)

Error using cplxpair (line 78)
Complex numbers can't be paired.

>> cplxpair (z2, 0.99)

ans =
   1.0e+03 *

>> cplxpair (z2, 1)

Error using cplxpair (line 41)
Relative tolerance TOL must be a scalar such that 0<=TOL<1.

>> cplxpair (z2, 2)

Error using cplxpair (line 41)
Relative tolerance TOL must be a scalar such that 0<=TOL<1.

Fri 06 May 2016 04:58:18 PM UTC, comment #1: 

This looks related to bug #45810 which was marked as fixed.

The Matlab documentation string for cplxpair is here (http://www.mathworks.com/help/matlab/ref/cplxpair.html) and it doesn't mention anything about the tolerance being in the range 0 to 1.

However, the description of tolerance is ambiguous.

A default tolerance of 100*eps relative to abs(A(i)) determines which numbers are real and which elements are paired complex conjugates.

I'm not sure exactly how to interpret that.  Octave has chosen to interpret it as

100 * eps (abs (A(i)))

But it would be quicker if we could calculate

100 * eps * abs (A(i))

It's not quite the same thing as you can see below

octave:1> eps (1000)
ans =    1.1369e-13
octave:2> eps*1000
ans =    2.2204e-13

In any case, Octave may have the correct default tolerance, but Matlab uses an entirely different method of determining the tolerance when a value is specified.

The only way to go about this is to test different inputs to the cplxpair function and see what happens.

Try the test case from bug #45810

z2 = [2000 * (1+eps) + 4j; 2000 * (1-eps) - 4j];

What do the following do under Matlab?

cplxpair (z2, -0.1)
cplxpair (z2, 0)
cplxpair (z2, 0.99)
cplxpair (z2, 1)
cplxpair (z2, 2)

If you are right that tolerance is in the range [0,1) then three of the statements should produce an error.

Rik <rik5>
Project Administrator
Fri 06 May 2016 12:33:22 PM UTC, original submission:  

The documentation for cplxpair was updated to say that the default value for tol is 100*eps (which matches the matlab documentation) but the matlab documentation also says that 0<= tol <1.  The 100*eps is the value of tol, not the multiplier of eps to compute tol.  The cplxpair code line 117 uses tol*eps but perhaps it should use eps/(1-tol)?  As an example, for matlab we use tol=0.0001 and octave errors unless we us 10000

development version from 5/6/16



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

Attach Files:

Attached Files
file #37145:  cplxpair.log added by gpetilli (3KiB - application/octet-stream - test results from comment #3 plus some more tests showing TOL is an absolute tolerance)


Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by gpetilli (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-08-29 rik5 StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2016-12-21 mtmiller Dependencies- => bugs #49900 is dependent
    2016-05-13 gpetilli Attached File- => Added cplxpair.log, #37145
    2016-05-11 rik5 Item GroupIncorrect Result => Matlab Compatibility
        StatusNeed Info => Confirmed
    2016-05-07 rik5 StatusNone => Need Info
    2016-05-06 rik5 Dependencies- => Depends on bugs #45810

    Back to the top

    Powered by Savane 3.5