File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed
Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -137,8 +137,12 @@ struct Normalμσ{T} <: Normal{T}
137137 σ:: T
138138end
139139
140- Normal(:: Type{T} = Float64) where {T} = Normal01{T}()
141- Normal(μ:: T , σ:: T ) where {T} = Normalμσ(μ, σ)
140+ const NormalTypes = Union{AbstractFloat,Complex{<: AbstractFloat }}
141+
142+ Normal(:: Type{T} = Float64) where {T<: NormalTypes } = Normal01{T}()
143+ Normal(μ:: T , σ:: T ) where {T<: NormalTypes } = Normalμσ(μ, σ)
144+ Normal(μ:: T , σ:: T ) where {T<: Real } = Normalμσ(AbstractFloat(μ), AbstractFloat(σ))
145+ Normal(μ, σ) = Normal(promote(μ, σ). .. )
142146
143147abstract type Exponential{T} <: Distribution{T} end
144148
150154
151155Exponential(:: Type{T} = Float64) where {T<: AbstractFloat } = Exponential1{T}()
152156Exponential(θ:: T ) where {T<: AbstractFloat } = Exponentialθ(θ)
157+ Exponential(θ:: Real ) = Exponentialθ(AbstractFloat(θ))
153158
154159
155160# # floats
Original file line number Diff line number Diff line change 116116
117117# # Normal & Exponential
118118
119- rand(rng:: AbstractRNG , :: SamplerTrivial{Normal01{T}} ) where {T<: Union{AbstractFloat,Complex{<:AbstractFloat}} } =
119+ rand(rng:: AbstractRNG , :: SamplerTrivial{Normal01{T}} ) where {T<: NormalTypes } =
120120 randn(rng, T)
121121
122122Sampler(RNG:: Type{<:AbstractRNG} , d:: Normal μσ{T}, n:: Repetition ) where {T} =
Original file line number Diff line number Diff line change @@ -6,8 +6,11 @@ using Test
66 # Normal/Exponential
77 @test rand(Normal()) isa Float64
88 @test rand(Normal(0.0 , 1.0 )) isa Float64
9+ @test rand(Normal(0 , 1 )) isa Float64
10+ @test rand(Normal(0 , 1.0 )) isa Float64
911 @test rand(Exponential()) isa Float64
1012 @test rand(Exponential(1.0 )) isa Float64
13+ @test rand(Exponential(1 )) isa Float64
1114 @test rand(Normal(Float32)) isa Float32
1215 @test rand(Exponential(Float32)) isa Float32
1316 @test rand(Normal(ComplexF64)) isa ComplexF64
You can’t perform that action at this time.
0 commit comments