-
-
Notifications
You must be signed in to change notification settings - Fork 17
Change the implementation of rotate!
to avoid unary minus
#1323
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
base: master
Are you sure you want to change the base?
Conversation
This looks fine to me, but is this case really encountered in practice where |
Probably not something people would use for real computations. 😅 But I imagine there will occasionally be folks exploring these edge cases just to see how the "strong zeroness" of |
Some chance that more of these functions ought to branch on zero. I don't see this documented, but |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1323 +/- ##
=======================================
Coverage 93.73% 93.73%
=======================================
Files 34 34
Lines 15746 15746
=======================================
Hits 14760 14760
Misses 986 986 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
From what I can tell, julia> mul!(ones(2,2), ones(2,2), fill(NaN,2,2), 3.0, false)
2×2 Matrix{Float64}:
NaN NaN
NaN NaN which shows that "strong zeroness" doesn't propagate in this case. But then we also have julia> rmul!(fill(NaN, 2,2), false)
2×2 Matrix{Float64}:
0.0 0.0
0.0 0.0
julia> lmul!(false, fill(NaN, 2,2))
2×2 Matrix{Float64}:
0.0 0.0
0.0 0.0
So yeah, behavior seems to vary a bit depending on the function. It might be too much to expect full consistency across all of |
That I agree |
The current implementation of
rotate!(x, y, c, s)
overwritesx
withc*x + s*y
andy
with-conj(s)*x + c*y
. There exists this edge case ofrotate!([NaN], [NaN], false, false)
The new
x
becomes0.0
, becausefalse
acts as a "strong zero" in Julia (sofalse * NaN == 0.0
). When calculating the newy
, the code executes-conj(false)*NaN + false*NaN
. However, the unary minus,-
, turns thefalse::Bool
to0::Int
, which is no longer a strong zero, and thus, we getNaN
. This is inconsistent withThis PR changes
-conj(s)*x + c*y
toc*y - conj(s)*x
to avoid unary minus, so thatI noted this from JuliaGPU/CUDA.jl#2607 (comment). More discussion in https://discourse.julialang.org/t/negative-false-no-longer-acts-as-a-strong-zero/128506/1