octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51059] hist3 function doesn't handle NaN inpu


From: anonymous
Subject: [Octave-bug-tracker] [bug #51059] hist3 function doesn't handle NaN inputs properly
Date: Thu, 18 May 2017 10:27:18 -0400 (EDT)
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

Follow-up Comment #2, bug #51059 (project octave):

So sorry, it seems my markup was malformed. One last try:

In statistics 1.3.0, hist3 doesn't appear to do the right thing for inputs
containing NaN values. The code appears to try to ignore input rows containing
NaN values, but instead it ends up turning the input matrix into a column
vector with NaNs removed.

Reproduce like this:

>> X = [1 1; nan 2; 3 1; 3 3; 1 nan; 3 1]
X =

     1     1
   NaN     2
     3     1
     3     3
     1   NaN
     3     1

>> result = hist3(X)
error: inits(2): out of bound 1
error: called from
    hist3>edges_from_nbins at line 190 column 11
    hist3 at line 121 column 24


I think the problem is on line 97:

94:  if (! ismatrix (X) || columns (X) != 2)
95:    error ("hist3: X must be a 2 columns matrix");
96:  endif
97:  X(any (isnan (X), 2)) = [];


Should be:

94:  if (! ismatrix (X) || columns (X) != 2)
95:    error ("hist3: X must be a 2 columns matrix");
96:  endif
97:  X(any (isnan (X), 2), :) = [];


Here's a unit test that exercises the NaN-suppression code:

%!test
%! D = [1 1; nan 2; 3 1; 3 3; 1 nan; 3 1];
%! [c, nn] = hist3 (D, {0:4, 0:4});
%! exp_c = zeros (5);
%! exp_c([7 9 19]) = [1 2 1];
%! assert (c, exp_c);
%! assert (nn, {0:4, 0:4});


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51059>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]