-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] MNT: Use fmax
when finding the maximum
#12005
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
Instead of adding an `if` to check for values that become the new max, simply use `fmax` to get the maximum and update the value. This improves readability. It may improve performance as `fmax` can be a single assembly instruction. Though most compilers can probably figure this out anyways.
fmax
when finding the maximumfmax
when finding the maximum
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 would be surprised if cython did not translate this usage of python max into fmax, fwiw
Was wondering that too, but found Cython translate it into a comparison like the one written. For example, Cython takes this function... cpdef float my_max(float a, float b) nogil:
return max(a, b) ...and turns the __pyx_t_1 = __pyx_v_b;
__pyx_t_2 = __pyx_v_a;
if (((__pyx_t_1 > __pyx_t_2) != 0)) {
__pyx_t_3 = __pyx_t_1;
} else {
__pyx_t_3 = __pyx_t_2;
}
__pyx_r = __pyx_t_3; (There's of course more C code that Cython generates that has been snipped for clarity.) |
fmax
when finding the maximumfmax
when finding the maximum
Have you submitted a PR to cython, then??
…On Wed, 5 Sep 2018 at 09:52, jakirkham ***@***.***> wrote:
Was wondering that too, but found Cython translate it into a comparison
like the one written. For example, Cython takes this function...
cpdef float my_max(float a, float b) nogil:
return max(a, b)
...and turns the max into this.
__pyx_t_1 = __pyx_v_b;
__pyx_t_2 = __pyx_v_a;
if (((__pyx_t_1 > __pyx_t_2) != 0)) {
__pyx_t_3 = __pyx_t_1;
} else {
__pyx_t_3 = __pyx_t_2;
}
__pyx_r = __pyx_t_3;
(There's of course more C code that Cython generates that has been snipped
for clarity.)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12005 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6x30eX6Tt5sedOhp4I1Hz0tYqLv_ks5uXxI2gaJpZM4WZsK2>
.
|
Nope. I can understand why they would want We could ask them about special casing |
Well, that's what I meant: they should be able to check statically if they
have a pair of floats. Would C compilers never optimise this case?
|
Instead of adding an `if` to check for values that become the new max, simply use `fmax` to get the maximum and update the value. This improves readability. It may improve performance as `fmax` can be a single assembly instruction. Though most compilers can probably figure this out anyways.
Instead of adding an `if` to check for values that become the new max, simply use `fmax` to get the maximum and update the value. This improves readability. It may improve performance as `fmax` can be a single assembly instruction. Though most compilers can probably figure this out anyways.
Instead of adding an
if
to check for values that become the new max, simply usefmax
to get the maximum and update the value. This improves readability. It may improve performance asfmax
can be a single assembly instruction. Though most compilers can probably figure this out anyways.