[MRG] MNT: Use fmax when finding the maximum#12005
[MRG] MNT: Use fmax when finding the maximum#12005qinhanmin2014 merged 1 commit intoscikit-learn:masterfrom
fmax when finding the maximum#12005Conversation
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
jnothman
left a comment
There was a problem hiding this comment.
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
ifto check for values that become the new max, simply usefmaxto get the maximum and update the value. This improves readability. It may improve performance asfmaxcan be a single assembly instruction. Though most compilers can probably figure this out anyways.