-
Notifications
You must be signed in to change notification settings - Fork 456
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
[Math] Fix NaN from powf() domain error. #2067
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks Bram, good catch. What do you think about moving the std::pow call down into the ternary operator, to avoid adding the extra std::max call?
In addition, I think this would fix the unit test errors. (You're clamping the value but the ternary expression needs the unclamped value.)
Hi Doug, I advise against the ternary operator... I checked, and the compilers (gcc, clang) actually produce more efficient code with See this godbolt output. |
I expected having a CLA in place for OpenImageIO with ASWF, would transfer over to OpenColorIO? |
Oops, did I break the unit test? I'll revisit. |
I was not proposing to replace the max with a new ternary. I was suggesting moving the pow call down into the existing ternary. As I mentioned, your unit tests are failing, so some action is needed. The CLAs for all ASWF projects are managed through the same account but need to be signed separately for each project. |
Thanks Doug, I will redo this PR. Strangely, the unmodified main branch fails the unit test as well. I have to find out what is going on here.
Does the main branch HEAD pass the unit tests for you? Thanks. |
All the tests should pass, except for the GPU tests on some mac platforms currently. |
This change prevents calling powf(x,y) with negative x. The SIMD versions using ssePower() already seem to be resistent to negative pixel values, but the scalar version was not. This would cause a SIGFPE on apps that have floating point exceptions enabled. FIXES: AcademySoftwareFoundation#2066 Signed-off-by: Bram Stolk <[email protected]>
I have changed this PR to be less invasive, and only correct the value passed to Note: I cannot get the unit test to pass on my machine, even when using HEAD of main. Pushed the PR to see if CI will pass. |
just to note, micro optimisation difference comes from the testing vs return order, if you flip the ternary around you can get the same code ... https://godbolt.org/z/Wzafa3nsb |
Can a maintainer please approve the CI run, and then merge? Thanks. |
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.
Hi Bram, what do you think about changing this:
out[0] = pixel[0]<=red[3] ? pixel[0] * red[4] : data[0];
to this:
out[0] = pixel[0]<=red[3] ? pixel[0] * red[4] :
std::pow(pixel[0] * red[0] + red[1], red[2]);
That way it avoids the extra branch.
No, that does not address the issue. We should not be feeding negative numbers to the base of a powf(). My change makes sure of that, your version does not. |
Hi Bram, Is the reason that you don't like my proposal because you are worried that |
This change prevents calling powf(x,y) with negative x.
The SIMD versions using ssePower() already seem to be resistent to negative pixel values, but the scalar version was not.
This would cause a SIGFPE on apps that have floating point exceptions enabled.
FIXES: #2066