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: anonymous
Subject: [Octave-bug-tracker] [bug #61143] Functions sum and mean returns wrong answer for single precision input
Date: Sat, 18 Sep 2021 18:20:43 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0

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

I'm not convinced that a change to sum() is necessary, but would like your
thoughts on this approach. Is this all that it takes?!


function s = recursivesum (x, depth=0)
  if (length(x) <= 3 || depth >= 7)
    s = sum(x);
  else
    s1 = recursivesum (x(1:4:end), depth+1);
    s2 = recursivesum (x(2:4:end), depth+1);
    s3 = recursivesum (x(3:4:end), depth+1);
    s4 = recursivesum (x(4:4:end), depth+1);
    s = s1+s2+s3+s4;
  end
endfunction


Results:

octave:28> clear all; t = ones(1,100e6,"single"); s = recursivesum(t),
class(s)
s =    1e+08
ans = single

octave:29> clear all; t = ones(1,100e6,"single"); s = sum(t), class(s)
s = 16777216
ans = single


This was based on the paper
(http://eprints.maths.manchester.ac.uk/2704/1/paper.pdf) linked to from the
Matlab link.

    _______________________________________________________

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]