Skip to content

Commit 8b3bac1

Browse files
jleugeriararslan
authored andcommitted
make quantile function of truncated distributions accept more than just Float64 arguments (#660)
* Changed the required argument type of the truncated distribution's quantile function from `::Float64` to the more general `::Real` * rather use subtype of than itself * added tests
1 parent 6abb7f5 commit 8b3bac1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/truncate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ insupport(d::Truncated{D,Union{Discrete,Continuous}}, x::Real) where {D<:Univari
4747

4848
### evaluation
4949

50-
quantile(d::Truncated, p::Float64) = quantile(d.untruncated, d.lcdf + p * d.tp)
50+
quantile(d::Truncated, p::Real) = quantile(d.untruncated, d.lcdf + p * d.tp)
5151

5252
for f in [:pdf, :logpdf, :cdf, :logcdf, :ccdf, :logccdf]
5353
@eval ($f)(d::Truncated, x::Int) = ($f)(d, float(x))

test/truncate.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ function verify_and_test(d::UnivariateDistribution, dct::Dict, n_tsamples::Int)
8484
# @test isapprox(cdf(d, Dual(x)) , cf, atol=sqrt(eps()))
8585
end
8686

87+
# test if truncated quantile function can be evaluated consistently for different types at certain points
88+
@test isapprox(quantile(d, 0), quantile(d, Float32(0)))
89+
@test isapprox(quantile(d, 1), quantile(d, Float32(1.0)))
90+
@test isapprox(quantile(d, Float64(0.3)), quantile(d, Float32(0.3)))
91+
@test isapprox(quantile(d, Float64(0.7)), quantile(d, Float32(0.7)))
92+
8793
try
8894
m = mgf(d,0.0)
8995
@test m == 1.0

0 commit comments

Comments
 (0)