[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #48690] basic statistics functions should retu
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input |
Date: |
Wed, 26 Jul 2017 13:07:48 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 |
Follow-up Comment #24, bug #48690 (project octave):
just want to confirm that yes, I don't have any tests checking the mode(X,DIM)
codepath, and it does fail there.
Matlab 2017a:
>> mode([])
Warning: MODE of a 0-by-0 matrix is NaN; result was an empty matrix in
previous
releases.
> In mode (line 69)
ans =
NaN
>> mode([],1)
ans =
1×0 empty double row vector
>> mode([],2)
ans =
0×1 empty double column vector
>> mode([],3)
ans =
[]
Octave 4.2.1 (release)
>> mode([])
ans = [](1x0)
>> mode([],1)
ans = [](1x0)
>> mode([],2)
ans = [](0x1)
>> mode([],3)
ans = [](0x0)
in my modified mode, it short circuits to NaN without checking dim:
>> mode([])
ans = NaN
>> mode([],1)
ans = NaN
>> mode([],2)
ans = NaN
>> mode([],3)
ans = NaN
the rest of your summary of the empty nD matrix handling is generally correct.
for all cases other than 0x0 the first nonsingleton dimension is changed to 1
and the rest are left alone.
The code does currently change the fist non-singleton dim (not just the first
dim greater than 1) to 1 with:
sz (find ((sz ~= 1), 1)) = 1;
and no need to use resize, since the output is just based on sz, not x. just
change sz(2) = 1. then it can move through the "not 0x0" codepath
as you said.
This, however, does create issues the dimensions of f and c. looking into
that now. I've appended a number of additional test based on matlab 2017a
output in addition to the ones that were already in there:
## Tests for empty input with DIM call
%!test
%! [m, f, c] = mode ([], 1);
%! assert (m, NaN (1,0));
%! assert (f, zeros (1,0));
%! assert (c, {(NaN (1,0))});
%!test
%! [m, f, c] = mode ([], 2);
%! assert (m, NaN (0,1));
%! assert (f, zeros (0,1));
%! assert (c, {(NaN (0,1))});
%!test
%! [m, f, c] = mode ([], 3);
%! assert (m, []);
%! assert (f, []);
%! assert (c, {});
%!test
%! [m, f, c] = mode (single([]), 1);
%! assert (m, single(NaN (1,0)));
%! assert (f, double(zeros (1,0)));
%! assert (c, {(NaN (1,0))});
%!test
%! [m, f, c] = mode (single([]), 2);
%! assert (m, single(NaN (0,1)));
%! assert (f, zeros (0,1));
%! assert (c, {(NaN (0,1))});
%!test
%! [m, f, c] = mode ([], 3);
%! assert (m, single([]));
%! assert (f, []);
%! assert (c, {});
%!test
%! [m, f, c] = mode (ones(0,0,1), 1);
%! assert (m, NaN (1,0));
%! assert (f, zeros (1,0));
%! assert (c, {(NaN (1,0))});
%!test
%! [m, f, c] = mode (ones(0,0,1), 2);
%! assert (m, NaN (0,1));
%! assert (f, zeros (0,1));
%! assert (c, {(NaN (0,1))});
%!test
%! [m, f, c] = mode (ones(0,0,1), 3);
%! assert (m, []);
%! assert (f, []);
%! assert (c, {});
%!test
%! [m, f, c] = mode (ones(1,0,1), 1);
%! assert (m, NaN (1,0));
%! assert (f, zeros (1,0));
%! assert (c, {(NaN (1,0))});
%!test
%! [m, f, c] = mode (ones(1,0,1), 2);
%! assert (m, NaN);
%! assert (f, 0);
%! assert (c, {(NaN (1,0))});
%!test
%! [m, f, c] = mode (ones(1,0,1), 3);
%! assert (m, NaN (1,0));
%! assert (f, zeros (1,0));
%! assert (c, {(NaN (1,0))});
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?48690>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Joel Dahne, 2017/07/20
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input,
Nicholas Jankowski <=
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26
- [Octave-bug-tracker] [bug #48690] basic statistics functions should return NaN on empty input, Nicholas Jankowski, 2017/07/26