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 random normals. #17725

Closed
wants to merge 1 commit into from

Conversation

fiatflux
Copy link

Implement complex normal random number generation, as discussed in #9836.

It ended up cleaner, at least on the git history side, to open a new PR rather than reopening #17443. Sorry if that makes things confusing otherwise!

@@ -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.7071067811865476),
Copy link
Contributor

@musm musm Jul 30, 2016

Choose a reason for hiding this comment

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

Last digit should be a 5: 0.7071067811865475

julia> 1/sqrt(BigFloat(2))
7.071067811865475244008443621048490392848359376884740365883398689953662392310596e-01
julia> 1/sqrt(2)
0.7071067811865475

Copy link
Author

Choose a reason for hiding this comment

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

Good catch.

@kshyatt kshyatt added domain:randomness Random number generation and the Random stdlib domain:complex Complex numbers labels Jul 30, 2016
@stevengj
Copy link
Member

stevengj commented Jul 31, 2016

LGTM. Hmm, some caveats below...

(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))
Copy link
Member

Choose a reason for hiding this comment

The 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 T. I think you want to use @eval and $T

@StefanKarpinski
Copy link
Sponsor Member

Are we going to include this in 0.5?

@tkelman
Copy link
Contributor

tkelman commented Aug 1, 2016

This is a new feature, albeit a small one. I don't think we should.

@stevengj
Copy link
Member

stevengj commented Sep 7, 2016

@fiatflux, now that master is Julia 0.6 we can look into merging this once the problems mentioned above are addressed. You also need to add an item to NEWS.md.

@tkelman tkelman added the needs news A NEWS entry is required for this change label Sep 7, 2016
@fiatflux
Copy link
Author

fiatflux commented Sep 8, 2016

Thanks @stevengj! I'm tied up with a proposal deadline right now but soon I'll be ready to do some comparative tests. My use case for this is performance sensitive, so I have a vested interest in ensuring it's snappy.

@tkelman tkelman mentioned this pull request May 13, 2017
@nsmith5 nsmith5 mentioned this pull request May 19, 2017
@fredrikekre
Copy link
Member

superseded by #21973

@KristofferC KristofferC removed the needs news A NEWS entry is required for this change label Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:complex Complex numbers domain:randomness Random number generation and the Random stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants