[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #59850] Add missing function "uniquetol"
From: |
Nicholas Jankowski |
Subject: |
[Octave-bug-tracker] [bug #59850] Add missing function "uniquetol" |
Date: |
Thu, 18 Nov 2021 12:08:36 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 |
Follow-up Comment #35, bug #59850 (project octave):
noticed a few things with nan's, empties, 'byrows' sorting, and nan with
OutputAllindices:
1) NaN:
matlab 2021a has what I think to be a bug for when A is all NaN (if anyone has
b to test and verify if it's still around...):
Matlab 2021a
>> uniquetol(NaN)
Error using uniquetol
Tolerance*DataSpace contained a NaN.
>> uniquetol([1 2 NaN])
ans =
1 2 NaN
>> uniquetol([1 2 NaN]')
ans =
1
2
NaN
>> uniquetol([1 2 NaN]', "byrows", true)
ans =
1
2
NaN
>> uniquetol([1 2 NaN], "byrows", true)
Error using uniquetol
Tolerance*DataSpace contained a NaN.
octave implementation thankfully doesn't have this, but it does produce:
>> uniquetol(NaN)
ans =
NaN
NaN
>> uniquetol(NaN, "byrows", true)
ans =
NaN
>> uniquetol([NaN NaN])
ans =>
NaN
NaN
NaN
>> uniquetol([NaN NaN]')
ans =>
NaN NaN NaN
> uniquetol([NaN NaN;NaN NaN])
ans =>
NaN NaN NaN NaN NaN
>> uniquetol([NaN NaN], "byrows",true)
ans =>
NaN NaN
>> uniquetol([NaN NaN]', "byrows",true)
ans =>
NaN
NaN
while there's nothing for a matlab comparison, it appears the line 259 block
that i'm assuming is correcting to preserve separate nans is miscalculating
when all(isnanA).
2) empties:
Matlab 2021a:
>> uniquetol(ones(0,0))
ans =
0×1 empty double column vector
>> uniquetol(ones(1,0))
ans =
1×0 empty double row vector
>> uniquetol(ones(0,1))
ans =
0×1 empty double column vector
>> uniquetol(ones(0,1,2))
ans =
0×1 empty double column vector
>> uniquetol(ones(1,0,2))
ans =
1×0 empty double row vector
>> uniquetol(ones(1,2,0))
ans =
1×0 empty double row vector
Octave:
>> uniquetol(ones(0,0))
ans = [](0x0)
>> uniquetol(ones(1,0))
ans = [](1x0)
>> uniquetol(ones(0,1))
ans = [](0x1)
>> uniquetol(ones(0,1,2))
ans = [](0x1x2)
>> uniquetol(ones(1,0,2))
ans = [](1x0x2)
>> uniquetol(ones(1,2,0))
ans = [](1x2x0)
just a bit diff with ByRows:
Matlab 2021a
>> uniquetol(ones(0,0), "byrows", true)
ans =
[]
>> size(ans)
ans =
0 0
>> uniquetol(ones(1,0), "byrows", true)
ans =
1×0 empty double row vector
>> uniquetol(ones(0,1), "byrows", true)
ans =
0×1 empty double column vector
>> uniquetol(ones(0,1,2), "byrows", true)
Error using uniquetol
With the ByRows option, inputs must be 2-D.
>> uniquetol(ones(1,0,2), "byrows", true)
Error using uniquetol
With the ByRows option, inputs must be 2-D.
>> uniquetol(ones(1,2,0), "byrows", true)
Error using uniquetol
With the ByRows option, inputs must be 2-D.
Octave:
>> uniquetol(ones(0,0), "byrows", true)
ans = [](0x0)
>> uniquetol(ones(1,0), "byrows", true)
ans = [](1x0)
>> uniquetol(ones(0,1), "byrows", true)
ans = [](0x1)
>> uniquetol(ones(0,1,2), "byrows", true)
ans = [](0x1x2)
>> uniquetol(ones(1,0,2), "byrows", true)
ans = [](1x0x2)
>> uniquetol(ones(1,2,0), "byrows", true)
ans = [](1x2x0)
hadn't seen the 2D check before, so:
Matlab 2021a:
>> uniquetol(cat(3,1,2,3,4,5), "byrows", true)
Error using uniquetol
With the ByRows option, inputs must be 2-D.
Octave:
>> uniquetol(cat(3,1,2,3,4,5), "byrows", true)
error: uniquetol: A must be a 2-D array when "ByRows" is true
error: called from
uniquetol at line 148 column 9
seems like isempty check may be a bit soon in the function if we wanted to
match this behavior. at the moment, it's "must be 2D unless empty"
3) byrows seems to not do sorting by 1st column like matlab:
Matlab 2021a:
>> a = [magic(3);magic(3)*2]
a =
8 1 6
3 5 7
4 9 2
16 2 12
6 10 14
8 18 4
>> uniquetol (a, 'byrows',true)
ans =
3 5 7
4 9 2
6 10 14
8 1 6
8 18 4
16 2 12
Octave:
>> a = [magic(3);2*magic(3)];
>> uniquetol(a,'byrows',true)
ans =
8 1 6
3 5 7
4 9 2
16 2 12
6 10 14
8 18 4
>> a([4 5],1) = NaN;
>> uniquetol(a,'byrows',true)
ans =
8 1 6
3 5 7
4 9 2
NaN 2 12
NaN 10 14
8 18 4
>> a(:,1) = NaN;
>> uniquetol(a,'byrows',true)
ans =
NaN 1 6
NaN 5 7
NaN 9 2
NaN 2 12
NaN 10 14
NaN 18 4
without byrows sorting is fine, but at least it seems to not compound with the
'all NaNs' issue above.
4) the same block that causes issues with all NaNs seems to also have issues
with OutputAllIndices for multiple NaNs:
Matlab 2021a:
>> a = [magic(3);magic(3)*2];
>> a(4:5) = NaN
a =
8 1 6
3 5 7
4 9 2
NaN 2 12
NaN 10 14
8 18 4
>> [c,ia,ic]=uniquetol (a, "OutputAllIndices",true)
c =
1
2
3
4
5
6
7
8
9
10
12
14
18
NaN
NaN
ia =
15×1 cell array
{[ 7]}
{2×1 double}
{[ 2]}
{2×1 double}
{[ 8]}
{[ 13]}
{[ 14]}
{2×1 double}
{[ 9]}
{[ 11]}
{[ 16]}
{[ 17]}
{[ 12]}
{[ 4]}
{[ 5]}
ic =
8
3
4
14
15
8
1
5
9
2
10
13
6
7
2
11
12
4
Octave:
>> [c ia ic]=uniquetol(a,"OutputAllIndices",true)
c =
1
2
3
4
5
6
7
8
9
10
12
14
18
NaN
NaN
ia =
{
[1,1] = 7
[1,2] =
10
15
[1,3] = 2
[1,4] =
3
18
[1,5] = 8
[1,6] = 13
[1,7] = 14
[1,8] =
1
6
[1,9] = 9
[1,10] = 11
[1,11] = 16
[1,12] = 17
[1,13] = 12
[1,14] =
4
5
[1,15] =
4
5
}
ic =
8
3
4
14
15
8
1
5
9
2
10
13
6
7
2
11
12
4
(note the duplication at the end of ia)
5) help text should probably also mention 'non-complex' in line 36.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?59850>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/