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

accept Number in Exponential #1691

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
13 changes: 9 additions & 4 deletions src/univariate/continuous/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ External links
* [Exponential distribution on Wikipedia](http://en.wikipedia.org/wiki/Exponential_distribution)

"""
struct Exponential{T<:Real} <: ContinuousUnivariateDistribution
struct Exponential{T<:Number} <: ContinuousUnivariateDistribution
θ::T # note: scale not rate
Exponential{T}(θ::T) where {T} = new{T}(θ)
end

function Exponential(θ::Real; check_args::Bool=true)
@check_args Exponential (θ, θ > zero(θ))
function Exponential(θ::Number; check_args::Bool=true)
@check_args(
Exponential,
(!(θ isa Complex), "Complex not allowed for θ"),
(isreal(θ), "θ must be a real number"),
(θ, θ > zero(θ)),
)
return Exponential{typeof(θ)}(θ)
end

Expand All @@ -37,7 +42,7 @@ Exponential() = Exponential{Float64}(1.0)
@distr_support Exponential 0.0 Inf

### Conversions
convert(::Type{Exponential{T}}, θ::S) where {T <: Real, S <: Real} = Exponential(T(θ))
convert(::Type{Exponential{T}}, θ::S) where {T <: Number, S <: Number} = Exponential(convert(T, θ))
function Base.convert(::Type{Exponential{T}}, d::Exponential) where {T<:Real}
return Exponential(T(d.θ))
end
Expand Down