|
|
Algorithm behind "sum" command?
Hi Matlab-ers,
Does anybody know whether the "sum" command is implemented by any
algorithm that is robust against round-off error? (e.g. the Kahan
algorithm). I need to repeatedly add very many numbers (3D arrays with
more than 2 million numbers). I could code some algorithm but don't
want to reinvent the wheel if Matlab already has a robust algorithm.
Thank you in advance for your help
Jomar
|
|
0
|
|
|
|
Reply
|
jomarbueyes (182)
|
11/18/2009 7:55:13 PM |
|
Jomar Bueyes <jomarbueyes@hotmail.com> wrote in message <607b592c-1993-4d66-904d-db1d170b4a15@k17g2000yqh.googlegroups.com>...
> Hi Matlab-ers,
>
> Does anybody know whether the "sum" command is implemented by any
> algorithm that is robust against round-off error? (e.g. the Kahan
> algorithm). I need to repeatedly add very many numbers (3D arrays with
> more than 2 million numbers). I could code some algorithm but don't
> want to reinvent the wheel if Matlab already has a robust algorithm.
Not that I'm aware of. Doing few experiments recently, I'm under impression that (in recent matlab) SUM splits large arrays into chunks, carry out the sum of chunks by multi-thread, each is sequentially added up, then gather the result together. The sum command is designed to perform the addition as fast as possible, period.
Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
11/18/2009 9:04:04 PM
|
|
Dear Jomar!
> Does anybody know whether the "sum" command is implemented by any
> algorithm that is robust against round-off error? (e.g. the Kahan
> algorithm). I need to repeatedly add very many numbers (3D arrays with
> more than 2 million numbers). I could code some algorithm but don't
> want to reinvent the wheel if Matlab already has a robust algorithm.
Sum with error compensation as fast Mex:
http://www.mathworks.com/matlabcentral/fileexchange/26800
While Kahan's method creates some (1 to 3) more valid digits for RAND and RANDN data, Knuth's methods perform the accumulation with quadrupel precision with a speed comparable to SUM (in a single thread).
Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
3/3/2010 6:26:04 PM
|
|
|
2 Replies
299 Views
(page loaded in 0.114 seconds)
|
|
|
|
|
|
|
|
|