bugGNU Octave - Bugs: bug #63203, std and var return 0 instead of...

 
 

bug #63203: std and var return 0 instead of NaN for some Inf and NaN inputs

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Wed 12 Oct 2022 07:54:58 PM UTC
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Tue 25 Oct 2022 08:53:51 PM UTC, comment #4: 

I ran this on default (52ccba0f1af9)
I got the same results as Matlab

Doug Stewart <dastew>
Sat 15 Oct 2022 01:44:01 PM UTC, comment #3: 

added BISTs that check Inf and NaN outputs for the the two-output form to default as:
http://hg.savannah.gnu.org/hgweb/octave/rev/94dc0f5ba8a3

marking as ready for test.

Nicholas Jankowski <nrjank>
Project Member
Sat 15 Oct 2022 12:49:47 PM UTC, comment #2: 

turned out to be a one line fix.  the 'error' was only occurring within the simplified codepath when the numel in direction dim was 1, which normally shortcut to retval = zeros(size(x)).  since the default branch still only has single output from var and std, adding a conditional " retval(isnan (x) | isinf (x)) = NaN " fixes that case and all tests below pass.

Added that bugfix to var, BISTs for the single output, and pushed to stable as:
http://hg.savannah.gnu.org/hgweb/octave/rev/3b16c2d90326

(will resolve the merge conflict then correct for the variable name change and add the two output tests to default)

Nicholas Jankowski <nrjank>
Project Member
Wed 12 Oct 2022 08:17:20 PM UTC, comment #1: 

forgot var also now gives an optional second output.  expected results for same tests below:

[v,m]=var(Inf)
[v,m]=var([1 2 Inf])
[v,m]=var([1 2 Inf]')
[v,m]=var([1 2 Inf],[],1)
[v,m]=var([1 2 Inf],[],2)
[v,m]=var([1 2 Inf; 2 3 4],[])
[v,m]=var([1 2 Inf; 2 3 Inf],[])

[v,m]=var(NaN)
[v,m]=var([1 2 NaN])
[v,m]=var([1 2 NaN]')
[v,m]=var([1 2 NaN],[],1)
[v,m]=var([1 2 NaN],[],2)
[v,m]=var([1 2 NaN; 2 3 4],[])
[v,m]=var([1 2 NaN; 2 3 NaN],[])

[v,m]=var([Inf 2 NaN])
[v,m]=var([Inf 2 NaN]')
[v,m]=var([Inf 2 NaN],[],1)
[v,m]=var([Inf 2 NaN],[],2)
[v,m]=var([1 2 Inf; 2 3 NaN],[])
[v,m]=var([1 2 NaN; 2 3 Inf],[])

in Matlab 2022b:

[v,m]=var(Inf)
v =
   NaN
m =
   Inf

[v,m]=var([1 2 Inf])
v =
   NaN
m =
   Inf

[v,m]=var([1 2 Inf]')
v =
   NaN
m =
   Inf

[v,m]=var([1 2 Inf],[],1)
v =
     0     0   NaN
m =
     1     2   Inf

[v,m]=var([1 2 Inf],[],2)
v =
   NaN
m =
   Inf

[v,m]=var([1 2 Inf; 2 3 4],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       Inf

[v,m]=var([1 2 Inf; 2 3 Inf],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       Inf

[v,m]=var(NaN)
v =
   NaN
m =
   NaN

[v,m]=var([1 2 NaN])
v =
   NaN
m =
   NaN

[v,m]=var([1 2 NaN]')
v =
   NaN
m =
   NaN

[v,m]=var([1 2 NaN],[],1)
v =
     0     0   NaN
m =
     1     2   NaN

[v,m]=var([1 2 NaN],[],2)
v =
   NaN
m =
   NaN

[v,m]=var([1 2 NaN; 2 3 4],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       NaN

[v,m]=var([1 2 NaN; 2 3 NaN],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       NaN

[v,m]=var([Inf 2 NaN])
v =
   NaN
m =
   NaN

[v,m]=var([Inf 2 NaN]')
v =
   NaN
m =
   NaN

[v,m]=var([Inf 2 NaN],[],1)
v =
   NaN     0   NaN
m =
   Inf     2   NaN

[v,m]=var([Inf 2 NaN],[],2)
v =
   NaN
m =
   NaN

[v,m]=var([1 2 Inf; 2 3 NaN],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       NaN

[v,m]=var([1 2 NaN; 2 3 Inf],[])
v =
    0.5000    0.5000       NaN
m =
    1.5000    2.5000       NaN

in Octave 8.0.0:

[v,m]=var(Inf)
v = 0
m = Inf

[v,m]=var([1 2 Inf])
v = NaN
m = Inf

[v,m]=var([1 2 Inf]')
v = NaN
m = Inf

[v,m]=var([1 2 Inf],[],1)
v =

   0   0   0

m =

     1     2   Inf

[v,m]=var([1 2 Inf],[],2)
v = NaN
m = Inf

[v,m]=var([1 2 Inf; 2 3 4],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      Inf

[v,m]=var([1 2 Inf; 2 3 Inf],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      Inf

[v,m]=var(NaN)
v = 0
m = NaN

[v,m]=var([1 2 NaN])
v = NaN
m = NaN

[v,m]=var([1 2 NaN]')
v = NaN
m = NaN

[v,m]=var([1 2 NaN],[],1)
v =

   0   0   0

m =

     1     2   NaN

[v,m]=var([1 2 NaN],[],2)
v = NaN
m = NaN

[v,m]=var([1 2 NaN; 2 3 4],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      NaN

[v,m]=var([1 2 NaN; 2 3 NaN],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      NaN

[v,m]=var([Inf 2 NaN])
v = NaN
m = NaN

[v,m]=var([Inf 2 NaN]')
v = NaN
m = NaN

[v,m]=var([Inf 2 NaN],[],1)
v =

   0   0   0

m =

   Inf     2   NaN

[v,m]=var([Inf 2 NaN],[],2)
v = NaN
m = NaN

[v,m]=var([1 2 Inf; 2 3 NaN],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      NaN

[v,m]=var([1 2 NaN; 2 3 Inf],[])
v =

   0.5000   0.5000      NaN

m =

   1.5000   2.5000      NaN

Nicholas Jankowski <nrjank>
Project Member
Wed 12 Oct 2022 07:54:58 PM UTC, original submission:  

i thought for sure this had been reported before, but didn't see it. (searching std and var are not the easiest terms to sift through.)

var is inconsistent in values returned from Inf and NaN inputs.  Matlab returns a NaN for all cases, but in 7.2.0 and 8.0.0:

>> var(Inf)
ans = 0

>> var([1 2 Inf])
ans = NaN

>> var([1 2 Inf]')
ans = NaN

>> var([1 2 Inf],[],1)
ans =

   0   0   0

>> var([1 2 Inf],[],2)
ans = NaN

>> var([1 2 Inf; 2 3 4],[])
ans =

   0.5000   0.5000      NaN

>> var([1 2 Inf; 2 3 Inf],[])
ans =

   0.5000   0.5000      NaN

(you get the exact same behavior with NaN instead of Inf on the inputs).  Matlab produces a NaN in all the cases above where Octave produces a 0.

looking through var now.  will at least add some tests/xtests to capture this if it doesn't look like a quick fix.

Nicholas Jankowski <nrjank>
Project Member

 

(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

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by dastew (Posted a comment)
  • -email is unavailable- added by nrjank (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 project members can vote.

     

     

     

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-26 nrjank Dependencies- bugs #55765 is dependent
    2022-10-26 nrjank StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2022-10-15 nrjank StatusIn Progress Ready For Test

    Back to the top


    Powered by Savane 3.9