-
Notifications
You must be signed in to change notification settings - Fork 415
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
Uniform overhaul #1045
base: master
Are you sure you want to change the base?
Uniform overhaul #1045
Conversation
If you think that we should keep the type of struct Uniform{T} <: ContinuousUnivariateDistribution
a::T
b::T
# Uniform{T}(a::T, b::T) constructor
function Uniform{T}(a::T, b::T; check_args=true) where {T <: Real}
check_args && @check_args(Uniform, a < b)
return new{T}(a, b)
end
# Abstract a,b - Uniform{T}(a, b) constructor
function Uniform{T}(a::Real, b::Real; check_args=true) where {T <: Real}
check_args && @check_args(Uniform, a < b)
return new{T}(T(a), T(b))
end
# Uniform{T}(a::T, b::T) constructor
function Uniform{T}(a::T, b::T) where {T <:Complex}
new{T}(a, b)
end
# Abstract a,b - Uniform{T}(a, b) constructor
function Uniform{T}(a, b) where {T <: Complex}
return new{T}(T(a), T(b))
end
end
# Real
# zeros() like constructor (Uniform(T, a::T, b::T))
function Uniform(::Type{T}, a::T, b::T; check_args=true) where {T <: Real}
return Uniform{T}(a, b, check_args = check_args)
end
# Abstract a,b - zeros() like constructor (Uniform(T, a, b))
function Uniform(::Type{T}, a, b; check_args=true) where {T <: Real}
return Uniform{T}(T(a), T(b), check_args = check_args)
end
# No type specified constructor:
function Uniform(a::Float64, b::Float64; check_args=true)
return Uniform{Float64}(a, b, check_args = check_args)
end
# Abstract a,b - no type specified constructor:
function Uniform(a, b; check_args=true)
return Uniform{Float64}(Float64(a), Float64(b), check_args = check_args)
end
# Complex
# zeros() like constructor (Uniform(T, a::T, b::T))
function Uniform(::Type{T}, a::T, b::T) where {T <: Complex}
return Uniform{T}(a, b)
end
# Abstract a,b - zeros() like constructor (Uniform(T, a, b))
function Uniform(::Type{T}, a, b) where {T <: Complex}
return Uniform{T}(T(a), T(b))
end
# No type specified constructor:
function Uniform(a::ComplexF64, b::ComplexF64)
return Uniform{ComplexF64}(a, b)
end
|
Codecov Report
@@ Coverage Diff @@
## master #1045 +/- ##
==========================================
+ Coverage 78.31% 78.31% +<.01%
==========================================
Files 112 112
Lines 5349 5350 +1
==========================================
+ Hits 4189 4190 +1
Misses 1160 1160
Continue to review full report at Codecov.
|
I don't support the changes here. Adding the a #1041 raises a discussion about the type returned by We should probably open a separate issue for discussing this or simply change the title of #1041 to cover all distributions. I see four possible behaviors for
I think 3. will add too much overhead without a real demand. I think I'd prefer one of the 1. options. |
I think 1a (always returning 2b (adding a type parameter to But it seems that 3., returning types following the parameters, is the most natural solution here. Especially since many distributions have "location" or "scale" parameters, which in a sense carry the "units" of the samples. I think this is what users expect (a couple of issues are requesting just this). I don't understand why this would be much more difficult than the 2b. approach? |
My five cents is also that option 3 is the most natural solution. I just attempted to switch a complex simulation over to Float32 for performance and Distributions.jl was the only blocker to that just working with no code changes. Having to add an argument specifically to allow Float32 seems unnecessary both for users and devs, when the parameters already contain the type information. |
Fixes #1041
Alternative branch: UniformOverhaul2