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
Ensure correct endian in numba_histogram #2678
Conversation
Question is, whether this affects any other functions that run numba? Namely
Probably, the would need a similar wrapper. |
hyperspy/misc/array_tools.py
Outdated
@@ -392,6 +391,17 @@ def numba_histogram(data, bins, ranges): | |||
hist : array | |||
The values of the histogram. | |||
""" | |||
if data.dtype.byteorder == '>': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the following instead?
if data.dtype.byteorder == '>':
data = data.byteswap().newbyteorder()
return _numba_histogram(data, bins, ranges)
It is the same, but easier to maintain...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, no problem.
Should I add it for the other 4 numba-functions? I think we cannot rule out that someone calls them with the wrong endian. For the private functions I could just add it to the calling functions, only lowess
would need a wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that numba only support native endianess and this approach will not work on all platform. What's about:
# Numba only supported native dtype
# https://github.com/numba/numba/issues/2243
if not data.dtype.isnative:
data = data.astype(data.dtype.type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that should do the job, indeed.
Codecov Report
@@ Coverage Diff @@
## RELEASE_next_patch #2678 +/- ##
======================================================
+ Coverage 76.62% 76.66% +0.04%
======================================================
Files 201 201
Lines 29655 29666 +11
Branches 6491 6495 +4
======================================================
+ Hits 22722 22743 +21
+ Misses 5174 5168 -6
+ Partials 1759 1755 -4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to take the opportunity to increase the coverage, thanks!
Not much, but at least a few obvious ones. In the end, I refrained from covering |
Description of the change
Makes sure that
numba_histogram
runs for big endian datatypes like>u2
or>f4
by converting data to little endian for execution.Closes #2668
Progress of the PR
Minimal example of the bug fix or the new feature