-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
clamp function should check that "lo" < "hi" #8006
Comments
See #8007 for a possible solution |
Tim Holy came up with a good compromise between speed and usability. The tension is between checking the bounds over and over again, (which is bad) and performing checking at all (which is good) so Tim suggested:
The only bad thing about this is that it's not quite as simple as just calling clamper = Clamp(lo, hi) # <--- This can throw an exception
output_data = [clamper(x) for x in input_data] |
If the clamp function, checks and all, is inlined, then the compiler will be able to hoist the check out of the loop (assuming the bounds are constant of course). Adding a ClampType is way too involved for such a simple function. |
Then the approach in #8007, (quick link to the diff) as long as inlining is possible, could be performant? |
If you really need it to be inlined and have trouble achieving that, see #8297. Fairly soon I hope to have another PR that will depend on that one. If no objections get raised in the meantime, that's the point I'll hit "merge." |
I don't like the idea of an "undefined" result for such a simple function as clamp. Would it really be too difficult to modify The latter ( |
What are you proposing that the effect of |
I feel there is an obvious implementation of clamp in terms of comparison |
Jeff There is no single obvious implementation -- there are two obvious implementations, depending on whether you perform the "min" or the "max" operation first. If you change the order, the result will differ iff minval>maxval. Actually, the OpenCL standard defines |
Stefan
|
Yes, +1 for the opengl approach. Obvious might not be the right word, but |
We basically have the same functionality as OpenCL right now, so should we just close this as |
agreed |
There could be a |
Hi,
playing around in math.jl I found that the clamp function does not check that "lo" is less than "hi", leading to unpredicted behaviour. For example clamp(5, 6, 4) returns 4, which I regard as a bug.
Cheers,
Davide
The text was updated successfully, but these errors were encountered: