-
-
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
Performance regression of scalar randn() between Julia 1.4 and 1.5 #37234
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,26 @@ julia> randn(rng, ComplexF32, (2, 3)) | |
0.611224+1.56403im 0.355204-0.365563im 0.0905552+1.31012im | ||
``` | ||
""" | ||
@inline randn(rng::AbstractRNG=default_rng()) = _randn(rng, rand(rng, UInt52Raw())) | ||
@inline function randn(rng::AbstractRNG=default_rng()) | ||
#= | ||
When defining | ||
`@inline randn(rng::AbstractRNG=default_rng()) = _randn(rng, rand(rng, UInt52Raw()))` | ||
the function call to `_randn` is currently not inlined, resulting in slightly worse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering whether it's really There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deduced it from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fix this, I would suggest moving this code duplication into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
performance for scalar random normal numbers than repeating the code of `_randn` | ||
inside the following function. | ||
=# | ||
@inbounds begin | ||
r = rand(rng, UInt52Raw()) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
# the following code is identical to the one in `_randn(rng::AbstractRNG, r::UInt64)` | ||
r &= 0x000fffffffffffff | ||
rabs = Int64(r>>1) # One bit for the sign | ||
idx = rabs & 0xFF | ||
x = ifelse(r % Bool, -rabs, rabs)*wi[idx+1] | ||
rabs < ki[idx+1] && return x # 99.3% of the time we return here 1st try | ||
return randn_unlikely(rng, idx, rabs, x) | ||
end | ||
end | ||
|
||
@inline function _randn(rng::AbstractRNG, r::UInt64) | ||
@inbounds begin | ||
|
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.
Trailing whitespace here.