octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #61143] Functions sum and mean returns wrong a


From: Michael Leitner
Subject: [Octave-bug-tracker] [bug #61143] Functions sum and mean returns wrong answer for single precision input
Date: Sat, 11 Sep 2021 16:58:06 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux i686; rv:60.0) Gecko/20100101 Firefox/60.0

Follow-up Comment #13, bug #61143 (project octave):

The issue is clear. However, reports like these raise the question whether it
wouldn't be better if single values are by default summed in double precision
(and at the end converted back). This uses neither more memory nor more
bandwidth, and according to my tests it is indeed perhaps even a bit faster.
It will obviously in the general case also be more correct, and as yet the
summation algorithm is not specified in the documentation, so we would be free
to change that. 

Further, what about summation of double values: as summing with "extra" takes
about two times as long as the default algorithm, I suspect that this uses
Kahan summation. This factor two is significant, so we won't like to use Kahan
summation per default. However, pairwise summation should be only
insignificantly slower than naive summation, consumes only O(log(N)) memory,
and would in general also be much more accurate. Julia seems to do it like
that: https://github.com/JuliaLang/julia/pull/4039 

So the question is whether we should accept a very small increase in
computation time (for pairwise summation of doubles, and perhaps no increase
at all for double summation of singles) and get much better accuracy per
default, thus not tripping up users that perhaps do not yet know What Every
Computer Scientist Should Know About Floating-Point Arithmetic. The option
"native" would remain, and for doubles could imply "naive". 

Of course this would apply also for cumsum, prod, cumprod, mean, var...

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61143>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]