-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dim_sum and sum returning a different result #126
Comments
This problem can be reproduced using this simple script:
which returns:
The correct result is |
Hi,
I can't explain it precisely, but it looks like the difference is due to
floating-point arithmetic. Try this simple change to your script and note
the results:
var = new((/12, 48, 720, 1440/), double)
var = 0.5d
Rick
…On Wed, Feb 12, 2020 at 2:06 AM Mattia Righi ***@***.***> wrote:
This problem can be reproduced using this simple script:
begin
var = new((/12, 48, 720, 1440/), float)
var = 0.5
total1 = sum(var)
total2 = dim_sum(dim_sum(dim_sum(dim_sum(var))))
print("total1 = " + total1)
print("total2 = " + total2)
end
which returns:
(0) total1 = 8.38861e+06
(0) total2 = 2.98598e+08
The correct result is total2, since 12x48x720x1440 x 0.5 = 2.98598e+08.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#126?email_source=notifications&email_token=ADLWOXSZRY323D5RB2PIOPLRCO3ZRA5CNFSM4KTVAPK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELP7SNA#issuecomment-585103668>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLWOXTKQGCQ4IWQZGG7QU3RCO3ZRANCNFSM4KTVAPKQ>
.
|
Hi @rbrownrigg, thanks for your answer. However, the problem occurs also for relatively small variables, e.g.:
which is surprising, also given that the corresponding |
Looks like the issue was floating point precision, and declaring var to be double solved the problem. So, I'm going to close this ticket. If there is a more fundamental problem, please open another ticket. |
Describe the bug
I'm encountering a strange behaviour of the
sum
function, which returns a different result thandim_sum
when applied to a 4 dimensional variable.Provide the following:
The 4 D variable
tmp
which I'm processing looks like this:The two sum statements I'm comparing are as follows:
and they return different values:
Note that the same operation with
avg
/dim_avg
gives identical results.Computing environment
The text was updated successfully, but these errors were encountered: