Find the test data on: http://s000.tinyupload.com/?file_id=80334866024724823452
% Unique elements of In_F
unF = unique(In_F);
% Out dimensions
sz = [size(In_F,1), length(unF)];
% row subs
[r,trash] = find(In_F ~= 0);
% col subs
In_F(In_F == 0) = [];
[trash, c] = ismember(In_F, unF);
% subs
K = [r,c.'];
% Val
In_Q(isnan(In_Q)) = [];
In_Q = In_Q(:);
% 1. Accumarray with default summation
Out1 = accumarray(K, In_Q, sz);
% 2. Accumarray with @sum
Out2 = accumarray(K, In_Q, sz,@sum);
% 3. Accumarray with default summation and fill
Out3 = accumarray(K, In_Q, sz,[],0);
isequalwithequalnans(Out1,Out2) % 0
isequalwithequalnans(Out3,Out2) % 1
isequalwithequalnans(Out1,Out3) % 0
% Roundoff errors
Roff = max(abs(Out1-Out3)) ./ max(abs(Out1));
What do you think about it? Am I missing something here?
Oleg
> Find the test data on: http://s000.tinyupload.com/?file_id=80334866024724823452
Note that this .mat file has two variables In_Q and In_F and its size is 1 Mb.
I haven't run your code, by I expect Mathworks reply would be: never rely on consistency SUM of because it depends on the order of the operations.
Bruno
% Create In_Q
In_Q = 54*rand(200,1000)-36;
In_Q(ceil(20000*rand(59000,1))) = NaN(59000,1);
% Create In_F
In_F = ceil(102*rand(200,1000));
In_F(isnan(In_Q)) = 0;
In_F = uint8(In_F);
% >>>>>>>>>>>>>>>SOME PREPARATIONS<<<<<<<<<<<<
% Unique elements of In_F
unF = unique(In_F);
% Out dimensions
sz = [size(In_F,1), length(unF)];
% row subs
[r,trash] = find(In_F ~= 0);
% col subs
In_F(In_F == 0) = [];
[trash, c] = ismember(In_F, unF);
% subs
K = [r,c.'];
% Val
In_Q(isnan(In_Q)) = [];
In_Q = In_Q(:);
% >>>>>>>>>>>>>CRUCIAL PART HERE<<<<<<<<<<<<<<<
% 1. Accumarray with default summation
Out1 = accumarray(K, In_Q, sz);
% 2. Accumarray with @sum
Out2 = accumarray(K, In_Q, sz,@sum);
% 3. Accumarray with default summation and fill
Out3 = accumarray(K, In_Q, sz,[],0);
isequalwithequalnans(Out1,Out2) % 0
isequalwithequalnans(Out3,Out2) % 1
isequalwithequalnans(Out1,Out3) % 0
% Roundoff errors
Roff = max(abs(Out1-Out3)) ./ max(abs(Out1));
% maxAbsoluteDiff
maxAbsDiff = max(abs(Out1-Out3));
Bruno
BTW thanks for the answers, good to know there's always someone willing to invest some of their time!
Oleg
Just did.
I get the same output of 0 1 0
r2009b, windows xp sp 2
Don't worry, I have no idea as to why it happens either. Perhaps Bruno
was right about the inconsistency of SUM.
-Nathan
I never occurs to me to suggest such thing. I suggested Mathworks adding an switch option where sum order can carried-out linearly, or at least rigorously specified. I wrote recently my request on Loren's blog (that's the only time I wrote to her blog - to show this feature really matters to me).
Bruno
The status of the service request has changed to "Bug/Enhancement Submitted"
Oleg
I took a closer look in our code and agree with you that these three
syntaxes should return identical answers.
Happy new years,
---Bob.
"Oleg Komarov" <oleg.k...@hotmail.it> wrote in message
news:hgiuuj$73n$1...@fred.mathworks.com...
Thanks for the reply Bob and happy new year.
Oleg