bugGNU Octave - Bugs: bug #49832, power operator produces different...

 
 

bug #49832: power operator produces different results between Matlab & Octave

Submitter:  None
Submitted:  Tue 13 Dec 2016 12:16:30 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Bawazeer Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 09 Mar 2021 06:46:19 PM UTC, comment #9: 

macOS backend library may be slightly different.

I went through the results of the power operator more carefully and I see these differences (M = Matlab, O = Octave).


1.^NaN = (NaN for M, 1 for O)
0.^-Inf = (Inf for M, NaN for O sometimes when done in matrix operations, but not for individual operation or scalar-by-matrix)
0.^0 = (1 for M, NaN for O sometimes when done in matrix operations, but not for individual operation or scalar-by-matrix)
0.^Inf = (0 for M, NaN for O sometimes when done in matrix operations, but not for individual operation or scalar-by-matrix)
(-eps(0)).^(-Inf) = (Inf for M, NaN for O)
(-eps(0)).^(-realmax) = (Inf for M, NaN for O)
(-eps(0)).^(realmax) = (0 for M, NaN for O)
(-eps(0)).^(Inf) = (0 for M, NaN for O)
(-realmin).^(-Inf) = (Inf for M, NaN for O)
(-realmin).^(-realmax) = (Inf for M, NaN for O)
(-realmin).^(realmax) = (0 for M, NaN for O)
(-realmin).^(Inf) = (0 for M, NaN for O)
-1.^(-realmax) = (1 for M, NaN for O)
-1.^(realmax) = (1 for M, NaN for O)
(-realmax).^realmax = (Inf for M, NaN for O)
(-realmax).^Inf = (Inf for M, NaN for O)
(-Inf) .^ (-Inf) = (0 for M, NaN for O)
(-Inf) .^ (-realmax) = (0 for M, NaN for O)
(-Inf).^0 = (1 for M, NaN for O, but not for individual operator)
(-Inf).^realmax = (Inf for M, NaN for O)
(-Inf).^Inf = (Inf for M, Nan for O)


Rik <rik5>
Group administrator
Tue 09 Mar 2021 06:46:25 AM UTC, comment #8: 

Hello Rik,

Used Janke's macOS version 6.1.0


Anonymous
Mon 08 Mar 2021 08:10:16 PM UTC, comment #7: 

For poster of comment #6, what operating system are you using?

For me,


[-Inf 0] .^ [-Inf 1]


returns


NaN - NaNi


for the first entry.  This is with a garden variety Ubuntu Linux system (20.04).

Rik <rik5>
Group administrator
Mon 08 Mar 2021 09:30:16 AM UTC, comment #6: 

With 6.1.0


>> -Inf .^ -Inf
ans = 0
>> [-Inf 0] .^ [-Inf 1]
ans =

   0   0


This matches the results from comment #3

Anonymous
Fri 16 Dec 2016 01:02:33 AM UTC, comment #5: 

I keep old versions of Octave around for testing and in 3.2.4 the result is correct (although it is complex which isn't right).  By version 3.4.3 the behavior has changed to return NaN + NaN i which is definitely wrong.

Rik <rik5>
Group administrator
Thu 15 Dec 2016 10:50:30 AM UTC, comment #4: 

I modify the program to test whether each power operation is complex.

for i=1:12
  for j=1:12
    iscomp(i,j)=~isreal(A(i).^A(j)); 
  end
end

I ran it on Matlab and attached the results. It is different from octave.

Also, I noted that matlab cut the value of +eps(0) or -eps(0) to
4.9^-324 when doing some operation (add sub mul  div) on those. This what I was referring to in my original submission. I gave the indecies where this happened exactly (in my original submission). However, I am not sure weather octave should do the same thing or no.




(file #39232)

Saleh <sabmab>
Thu 15 Dec 2016 09:10:04 AM UTC, comment #3: 

In Matlab 2014 I see


-Inf .^ -Inf

ans = 0


and


[-Inf 0] .^ [-Inf 1]
ans =

     0     0


I would keep the signed 0, but since isreal(Inf)=1 and real powers of real numbers are real numbers, [-Inf 0] .^ [-Inf 1] should be real.

Marco Caliari <caliari>
Group Member
Tue 13 Dec 2016 05:12:45 AM UTC, comment #2: 

The only difference I see is with the power operator.  For the other matrices, I used 'isequaln' which compares equality with NaN comparing equal to NaN.  Because of the NaNs one can't use the equality operator '==', subtraction, or isequal, to determine if the matrices are equal.

For the power operator, there are differences between how the operator is computed for scalars and matrices.

For example,


-Inf .^ -Inf
ans = -0


But,


[-Inf 0] .^ [-Inf 1]
ans =

   NaN - NaNi     0 +   0i

 


Rik <rik5>
Group administrator
Tue 13 Dec 2016 12:37:49 AM UTC, comment #1: 

It's a little too hard to debug what is going on here.  Can you run this script under Matlab and upload the resulting mat file?


clear all;

A=[-inf -realmax -1 -realmin -eps(0) 0 +eps(0) +realmin +1 +realmax +inf nan];

summ=repmat(A,12,1) +repmat(A',1,12);

subb=repmat(A,12,1) -repmat(A',1,12);

mull=repmat(A,12,1).*repmat(A',1,12);

divv=repmat(A,12,1)./repmat(A',1,12);

poww=repmat(A,12,1).^repmat(A',1,12);

isfin = isfinite(poww))

save tstvar.mat



Rik <rik5>
Group administrator
Tue 13 Dec 2016 12:16:30 AM UTC, original submission:  


specially the power operation is totally different from matlab 2014.
octave version 4.3.0+


A=[-inf -realmax -1 -realmin -eps(0) 0 +eps(0) +realmin +1 +realmax +inf nan];

summ=repmat(A,12,1) +repmat(A',1,12);
%elements that are different from matlab
%(5,5) (6,5) (7,6) (5,6) (7,7) (6,7)

subb=repmat(A,12,1) -repmat(A',1,12);
%elements that are different from matlab
%(6,5) (7,5) (7,6) (5,6) (6,7) (5,7)

mull=repmat(A,12,1).*repmat(A',1,12);
%elements that are different from matlab
%(7,3) (5,3) (3,5) (9,5) (3,7) (9,7) (7,9) (5,9)

divv=repmat(A,12,1)./repmat(A',1,12);
%elements that are different from matlab
%(3,5) (9,5) (3,7) (9,7)

poww=repmat(A,12,1).^repmat(A',1,12);
%elements that are different from matlab
%almost all of them

%compare this fogure between octave and matlab
% matlab figure seems more logical
spy(isfinite(poww))


Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #39232:  tstvar2.mat added by sabmab (1KiB - application/octet-stream)
file #39209:  tstvar.mat added by None (1KiB - application/octet-stream - attached the results on matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by sabmab (Updated the item)
  • -email is unavailable- added by caliari (Posted a comment)
  • -email is unavailable- added by rik5 (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-12-15 sabmab Attached File- Added tstvar2.mat, #39232
    2016-12-13 rik5 StatusNeed Info Confirmed
        Summaryoperations on double limites are not compatiable to matlab power operator produces different results between Matlab & Octave
    2016-12-13 None Attached File- Added tstvar.mat, #39209
    2016-12-13 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code