bugGNU Octave - Bugs: bug #50553, eps with imaginary argument gives...

 
 

bug #50553: eps with imaginary argument gives wrong value

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Wed 15 Mar 2017 09:27:34 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 16 Mar 2017 03:30:46 PM UTC, comment #3: 

The patch works.  I'm going to mark this as fixed and close the report.  However, it has exposed a horrible performance issue.  The C++ code is 350X slower than an m-file implementation.  I've filed bug #50561 about that.

Rik <rik5>
Group administrator
Thu 16 Mar 2017 12:59:58 PM UTC, comment #2: 

I pushed the following changeset.  If the result is based on abs of the argument and not looking at real and imaginary parts separately, then I think this should be sufficient.

http://hg.savannah.gnu.org/hgweb/octave/rev/953cb077757c

John W. Eaton <jwe>
Group administrator
Thu 16 Mar 2017 12:00:13 AM UTC, comment #1: 

Confirmed.  The function eps is written in C++ and is located in libinterp/corefcn/data.cc.  The bit of code which is the problem is


          Array<double> x = args(0).array_value ();

          Array<double> epsval (x.dims ());

          for (octave_idx_type i = 0; i < x.numel (); i++)
            {
              double val = ::fabs (x(i));
              if (octave::math::isnan (val) || octave::math::isinf (val))
                epsval(i) = lo_ieee_nan_value ();
              else if (val < std::numeric_limits<double>::min ())
                epsval(i) = pow (2.0, -1074e0);
              else
                {
                  int expon;
                  octave::math::frexp (val, &expon);
                  epsval(i) = std::pow (2.0,
                                        static_cast<double> (expon - 53));
                }

              retval = epsval;
            }


The first line asks for "array_value" which produces an array of doubles (and thus only the real part).  It seems that this needs to be broken up in to two sections.


  if (args(0).is_complex_type)
    {
      // Different calculation for complex
    }
  else
    {
       // Existing code
    }


I don't know if the best strategy is to declare a complex NDArray and then use the abs() function to produce a real NDArray and then iterate through that.  Or whether we should be using Array directly.



Rik <rik5>
Group administrator
Wed 15 Mar 2017 09:27:34 PM UTC, original submission:  

MATLAB:

>> clear all
>> eps(0)
ans =
  4.9407e-324

>> eps(1)
ans =
   2.2204e-16

>> eps(i)
ans =
   2.2204e-16

>> eps(1+i)
ans =
   2.2204e-16

>> eps(1e9+i)
ans =
   1.1921e-07

>> eps(1e9i)
ans =
   1.1921e-07

>> eps(1e9+1e9i)
ans =
   2.3842e-07

>> eps(abs(1e9+1e9i))
ans =
   2.3842e-07



Octave 4.2.1

>> clear all
>> eps(0)
ans =   4.9407e-324

>> eps(1)
ans =    2.2204e-16

>> eps(i)
ans =   4.9407e-324

>> eps(1+i)
ans =    2.2204e-16

>> eps(1e9+i)
ans =    1.1921e-07

>> eps(1e9i)
ans =   4.9407e-324

>> eps(1e9+1e9i)
ans =    1.1921e-07

>> eps(abs(1e9+1e9i))
ans =    2.3842e-07


Short story: MATLAB eps() function seems to be based on abs(arg) whereas Octave only looks at real(arg).

Fix: need to take abs() of argument to eps() function.

Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Date Changed by Updated Field Previous Value => Replaced by
    2017-03-16 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
        Release4.2.1 dev
    2017-03-16 jwe StatusConfirmed Ready For Test
    2017-03-16 rik5 CategoryNone Octave Function
        Item GroupNone Matlab Compatibility
        StatusNone Confirmed
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code