diff --git a/src/univariate/continuous/logitnormal.jl b/src/univariate/continuous/logitnormal.jl index 7fd5fb911..80e296c8b 100644 --- a/src/univariate/continuous/logitnormal.jl +++ b/src/univariate/continuous/logitnormal.jl @@ -72,6 +72,9 @@ LogitNormal(μ::Real=0.0) = LogitNormal(μ, one(μ); check_args=false) @distr_support LogitNormal 0.0 1.0 #insupport(d::Union{D,Type{D}},x::Real) where {D<:LogitNormal} = 0.0 < x < 1.0 +# # TODO change @distr_support to generate functions that respect the type parameter +# minimum(::LogitNormal{T}) where T = T(0) +# maximum(::LogitNormal{T}) where T = T(1) #### Conversions convert(::Type{LogitNormal{T}}, μ::S, σ::S) where diff --git a/src/univariate/locationscale.jl b/src/univariate/locationscale.jl index 97e47d6f7..54ba2d319 100644 --- a/src/univariate/locationscale.jl +++ b/src/univariate/locationscale.jl @@ -49,12 +49,19 @@ 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} + #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 @@ -62,7 +69,9 @@ 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) diff --git a/test/univariate/locationscale.jl b/test/univariate/locationscale.jl index 761ce55bb..f7ac5b6c6 100644 --- a/test/univariate/locationscale.jl +++ b/test/univariate/locationscale.jl @@ -170,3 +170,13 @@ end @test ls_norm isa LocationScale{Float64, Continuous, Normal{Float64}} @test ls_norm isa Distributions.AffineDistribution{Float64, Continuous, Normal{Float64}} end + + +@testset "user specified type Float32" begin + dln = LogitNormal(0f0, sqrt(2f0)) + lower, upper = 1f0, 3f0 + d = Distributions.AffineDistribution(lower, (upper -lower), dln, partype(dln)) + @test scale(d) isa Float32 + #@test minimum(d) isa Float32 # minimum is more complicated + #plot(d) +end; \ No newline at end of file