Skip to content
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 randn #21973

Merged
merged 5 commits into from
May 25, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add where syntax and move to appropriate place in source
  • Loading branch information
Nathan Smith committed May 20, 2017
commit 2da70cccce9026b3347889abd0f69470459a5ad4
7 changes: 4 additions & 3 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,6 @@ complex normal distribution.
end
end

Base.@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))

# this unlikely branch is put in a separate function for better efficiency
function randn_unlikely(rng, idx, rabs, x)
@inbounds if idx == 0
Expand Down Expand Up @@ -1287,6 +1284,10 @@ let Floats = Union{Float16,Float32,Float64}
$randfun( dims::Integer... ) = $randfun(GLOBAL_RNG, Float64, dims...)
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line inserted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, not sure how that got there..

# complex randn
Base.@irrational SQRT_HALF 0.7071067811865475244008 sqrt(big(0.5))
randn(rng::AbstractRNG, ::Type{Complex{T}}) where {T <: Floats} = Complex{T}(SQRT_HALF * randn(rng, T), SQRT_HALF*randn(rng, T))
Copy link
Member

@rfourquet rfourquet May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want T<:Floats or T<:AbstractFloat. E.g. if someone defines randn(::CustomRNG, ::BigFloat), she won't benefit from your complex randn definition...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be AbstractFloat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, also added a statement to the NEWS

end

## random UUID generation
Expand Down