-
-
Notifications
You must be signed in to change notification settings - Fork 11k
BUG: shift operator cycles, fixes #2449 #7473
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
Conversation
|
||
#define LEFT_SHIFT_OP \ | ||
do { \ | ||
if (NPY_LIKELY(in2 < sizeof(@type@) * 8)) { \ |
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.
I think there are number of bits macros defined somewhere... yep, in npy_common.h
. The have the form NPY_BITSOF_LONGLONG
etc.
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.
Probably already included here.
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.
Please, kill the macro ;)
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.
Does this actually buy speed over ...? ... : ...
?
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.
A cleaner version modulo signedness might be
#define LEFT_SHIFT = do {*out = NPY_LIKELY(in2 < NPY_BITSOF_@TYPE@) ? in1 << in2 : 0} while(0)
Although I don't think we actually need the do ... while(0)
bit here.
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.
Macro removed in #13739. Kept the if statements because I think they're clearer. Did not use NPY_BITS_OF_LONG
and friends because they don't exist for NPY_BITS_OF_ULONG
etc.
Might want to also check the scalar math in |
{ | ||
if (IS_BINARY_REDUCE) { | ||
BINARY_REDUCE_LOOP(@type@) { | ||
@type@ ip2_val = *(@type@ *)ip2; |
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.
Could remove the reduce specialization, I suspect reduce using the shift operators would be rare and BINARY_LOOP_FAST
should have adequate performance.
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.
Done in #13739
Be good to finish this up for 1.12. |
@jaimefrio How is your time looking? |
I'll take a look at it during this week/weekend. |
@jaimefrio Waiting... If you don't have the time let me know and I'll try to fix it up. |
☔ The latest upstream changes (presumably #7980) made this pull request unmergeable. Please resolve the merge conflicts. |
I wanted to get this into 1.12 but don't have the time at the moment, so pushing off to 1.13. |
Pushed off to 1.15. |
@jaimefrio - ping? |
Pushing off again. |
Pushed off again. |
I don't have permissions to push fixups to this branch, so I fixed the conflicts and addressed comments in gh-13739 |
@eric-wieser OK, closing this. |
This: * Inlines the macros in loops.c.src * Replaces 8 with `CHAR_BIT `. The `NPY_SIZEOF_*` macros are not used here because it's too much work to apply them to the signed types, and they expand to the same thing anyway. * Removes the reduce loop specializations which likely no one cares about * Uses pytest.mark.parametrize to shorten the test
#2449