-
Notifications
You must be signed in to change notification settings - Fork 419
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
allow specify parameter type in AffineDistribution #1769
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,20 +49,29 @@ struct AffineDistribution{T<:Real, S<:ValueSupport, D<:UnivariateDistribution{S} | |
end | ||
end | ||
|
||
function AffineDistribution(μ::T, σ::T, ρ::UnivariateDistribution; check_args::Bool=true) where {T<:Real} | ||
function AffineDistribution(μ::T, σ::T, ρ::UnivariateDistribution, _T::Type; check_args::Bool=true) where {T<:Real} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of this approach - if users want to set the types specifically, they can just call one of the internal constructors. Can't we just replace line 54 with _T = promote_type(partype(ρ), T) BTW note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @devmotion for this aid. I already tried making AffineTransformation using partype instead of eltype and it caused problems/failing tests with the discretenonparametric distribution. I can prepare a pull request with the change and we can look, whether the failing discretenonparametric tests are reasonable (expecting rationals that are promoted to float with the change) The deeper problem to me is that AffineTransformation transforms both, parameter-based quantities and samples. I think we should keep these two types separate (#1433) |
||
#workaround ##1765 to allow specifying Float32 as parametric type | ||
@check_args AffineDistribution (σ, !iszero(σ)) | ||
_T = promote_type(eltype(ρ), T) | ||
return AffineDistribution{_T}(_T(μ), _T(σ), ρ) | ||
end | ||
|
||
function AffineDistribution(μ::T, σ::T, ρ::UnivariateDistribution; check_args::Bool=true) where {T<:Real} | ||
#@check_args AffineDistribution (σ, !iszero(σ)) | ||
_T = promote_type(eltype(ρ), T) | ||
#_T = promote_type(partype(ρ), T) breakes DiscreteNonParametric | ||
return AffineDistribution(μ, σ, ρ, _T) | ||
end | ||
|
||
function AffineDistribution(μ::Real, σ::Real, ρ::UnivariateDistribution; check_args::Bool=true) | ||
return AffineDistribution(promote(μ, σ)..., ρ; check_args=check_args) | ||
end | ||
|
||
# aliases | ||
const LocationScale{T,S,D} = AffineDistribution{T,S,D} | ||
function LocationScale(μ::Real, σ::Real, ρ::UnivariateDistribution; check_args::Bool=true) | ||
Base.depwarn("`LocationScale` is deprecated. Use `+` and `*` instead", :LocationScale) | ||
Base.depwarn( | ||
"`LocationScale` is deprecated. Use `+` and `*` instead " * | ||
"(see ?Distributions.AffineDistribution)", :LocationScale) | ||
# preparation for future PR where I remove σ > 0 check | ||
@check_args LocationScale (σ, σ > zero(σ)) | ||
return AffineDistribution(μ, σ, ρ; check_args=false) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.