Skip to content
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

Fix issue with sum on float32 arrays being impacted by chunk size. #8

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

mdales
Copy link
Contributor

@mdales mdales commented Nov 5, 2024

It was spotted that when summing a float32 layer, the answer didn't match if you summed the entire layer directly using numpy. Worse, the result varied slightly depending on the size of YSTEP.

The root cause was that the accumulator in sum was a float64, so both types ended up being involved in the equation, so there was mixing of precisions that lead to different results.

Now if you sum a float32 layer we force maximum precision by moving everything to float64. This makes sense as the final result was always float64 (a debatable position, perhaps it should match the layer type, but that's for a discussion for another podcast). This also matches the result in QGIS, which is probably useful also.

It was spotted that when summing a float32 layer, the answer didn't
match if you summed the entire layer directly using numpy. Worse, the
result varied slightly depending on the size of YSTEP.

The root cause was that the accumulator in sum was a float64, so
both types ended up being involved in the equation, so there was
mixing of precisions that lead to different results.

Now if you sum a float32 layer we force maximum precision by
moving everything to float64. This makes sense as the final result
was always float64 (a debatable position, perhaps it should match
the layer type, but that's for a discussion for another podcast).
This also matches the result in QGIS, which is probably useful
also.
@mdales mdales merged commit 75ff7be into main Nov 6, 2024
1 check passed
@mdales mdales deleted the mwd-fix-chunk-impact-on-sum-float32 branch November 6, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant