-
-
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
Add complex random normals. #17725
Add complex random normals. #17725
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 |
---|---|---|
|
@@ -1123,7 +1123,10 @@ const ziggurat_exp_r = 7.6971174701310497140446280481 | |
Generate a normally-distributed random number of type `T` with mean 0 and standard deviation 1. | ||
Optionally generate an array of normally-distributed random numbers. | ||
The `Base` module currently provides an implementation for the types | ||
`Float16`, `Float32`, and `Float64` (the default). | ||
`Float16`, `Float32`, `Float64` (the default), `Complex32`, `Complex64`, and `Complex128`. | ||
When the type argument is complex, the values returned are drawn from the circularly symmetric | ||
complex normal distribution. | ||
. | ||
""" | ||
@inline function randn(rng::AbstractRNG=GLOBAL_RNG) | ||
@inbounds begin | ||
|
@@ -1224,6 +1227,14 @@ let Floats = Union{Float16,Float32,Float64} | |
$randfun( dims::Integer... ) = $randfun(GLOBAL_RNG, Float64, dims...) | ||
end | ||
end | ||
|
||
for (T,SQRT_HALF) in ((Float64, 0.7071067811865475), | ||
(Float32, 0.70710677f0), | ||
(Float16, 0.70710677f0)) | ||
@inline function randn(rng::AbstractRNG, ::Type{Complex{T}}) | ||
Complex{T}(SQRT_HALF*randn(rng, T), SQRT_HALF*randn(rng, T)) | ||
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. Actually, this doesn't seem right to me.... you're defining the function in terms of the global variable |
||
end | ||
end | ||
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. It seems better to have: @irrational SQRT_HALF 0.7071067811865475244008 sqrt(big(0.5))
randn{T}(rng::AbstractRNG, ::Type{Complex{T}}) = Complex{T}(SQRT_HALF*randn(rng, T), SQRT_HALF*randn(rng, T)) That way, it will work automatically for any real type Also, this is less code. 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. You could also write 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. It won't inline it for 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. True, but for |
||
end | ||
|
||
## random UUID generation | ||
|
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.
extra period here