[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-patch-tracker] [patch #10103] Add weighted standard deviation fe
From: |
Nicholas Jankowski |
Subject: |
[Octave-patch-tracker] [patch #10103] Add weighted standard deviation feature to 'std' |
Date: |
Mon, 1 Nov 2021 23:44:56 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 |
Follow-up Comment #14, patch #10103 (project octave):
Ok, I'm noticing a number of test failures.
before making a patch, always run 'test <function>' to be sure there aren't
any surprises.
a few seem to be %!error tests in std that just needed variable names or error
message text updated now that var is generating the messages:
Expected <OPT must be 0 or 1>, but got <var: W must be 0 or 1 or a vector of
positive integers>
Expected <DIM must be an integer>, but got <var: DIM must be a positive
integer scalar, vector, or 'all'>
Easy enough to fix. but more importantly, both var and std have issues with
empty array handling:
While you force var([]) and std([]) to return NaN like matlab using an
'isempty', this fails the following test in std:
>> test std
***** assert (std (ones (1,3,0,2)), ones (1,3,0,2))
!!!!! test failed
ASSERT errors for: assert (std (ones (1, 3, 0, 2)),ones (1, 3, 0, 2))
Location | Observed | Expected | Reason
. O(1x1) E(1x3x0x2) Dimensions don't match
Empty arrays can have dimensionality, and that can matter if we want to
maintain mathematical consistency:
https://octave.org/doc/latest/Empty-Matrices.html
it turns out that the test above is actually incorrect in matlab, and it
should be:
assert (std (ones (1,3,0,2)), ones (1,1,0,2))
Maybe that was a matlab change as they not too long ago tried to bring
consistency to their NaN and empty array handling throughout all of their
functions. if dim=1 you get ones(1,3,0,2), but if dim=2, you don't.
There should be, but isn't a corresponding test in var.
So, noting that the same empty array can be created with NaN(1,0). i think in
the past rather than just check isempty I did something like:
i did something like
if isempty(x)
outsize = size(x);
outsize(dim)=1;
retval = NaN(outsize);
else
...
Now, that's not quite enough of course. because in matlab the empty array
processing seems to crash into the 2D vector handling algorithm. see all the
following:
Matlab 2021a:
>> var([])
ans =
NaN
>> var([],[],1)
ans =
1×0 empty double row vector
>> var([],[],2)
ans =
0×1 empty double column vector
>> var([],[],3)
ans =
[]
>> std(ones(0,0))
ans =
NaN
>> std(ones(1,0))
ans =
NaN
>> std(ones(0,1))
ans =
NaN
>> std(ones(1,0),[],1)
ans =
1×0 empty double row vector
>> std(ones(1,0),[],2)
ans =
NaN
>> std(ones(0,1),[],1)
ans =
NaN
>> std(ones(0,1),[],2)
ans =
0×1 empty double column vector
and adding in the nd array handling:
>> std(ones(1,3,0,2),[],1)
ans =
1×3×0×2 empty double array
>> std(ones(1,3,0,2),[],2)
ans =
1×1×0×2 empty double array
>> std(ones(1,3,0,2),[],3)
ans(:,:,1,1) =
NaN NaN NaN
ans(:,:,1,2) =
NaN NaN NaN
>> std(ones(1,3,0,2),[],4)
ans =
1×3×0 empty double array
there's quite a few things to try to capture. again, let me look at how I
handled something similar before and i'll see if it can just drop in here.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/patch/?10103>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/