Skip to content

Commit f13b618

Browse files
authored
Ensure that binomlogpdf returns non-positive values, t distributions with infinite parameter are supported, and add integration tests (#126)
* Ensure that `binomlogpdf` returns non-positive values * Add test * Add integration test * Bump version * Handle student t distribution with infinite `ν`
1 parent e3fe89d commit f13b618

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: IntegrationTest
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
tags: '*'
11+
12+
jobs:
13+
test:
14+
name: ${{ matrix.package.repo }}/${{ matrix.package.group }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
julia-version: [1]
20+
os: [ubuntu-latest]
21+
package:
22+
- {user: JuliaStats, repo: Distributions.jl}
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
- uses: julia-actions/setup-julia@v1
27+
with:
28+
version: ${{ matrix.julia-version }}
29+
arch: x64
30+
- uses: julia-actions/julia-buildpkg@latest
31+
- name: Clone Downstream
32+
uses: actions/checkout@v2
33+
with:
34+
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
35+
path: downstream
36+
- name: Load this and run the downstream tests
37+
shell: julia --color=yes --project=downstream {0}
38+
run: |
39+
using Pkg
40+
try
41+
# force it to use this PR's version of the package
42+
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
43+
Pkg.update()
44+
Pkg.test() # resolver may fail with test time deps
45+
catch err
46+
err isa Pkg.Resolve.ResolverError || rethrow()
47+
# If we can't resolve that means this is incompatible by SemVer and this is fine
48+
# It means we marked this as a breaking change, so we don't need to worry about
49+
# Mistakenly introducing a breaking change, as we have intentionally made one
50+
@info "Not compatible with this release. No problem." exception=err
51+
exit(0) # Exit immediately, as a success
52+
end

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StatsFuns"
22
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
3-
version = "0.9.11"
3+
version = "0.9.12"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/distrs/binom.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ binompdf(n::Real, p::Real, k::Real) = exp(binomlogpdf(n, p, k))
1919
binomlogpdf(n::Real, p::Real, k::Real) = binomlogpdf(promote(n, p, k)...)
2020
function binomlogpdf(n::T, p::T, k::T) where {T<:Real}
2121
m = clamp(k, 0, n)
22-
val = betalogpdf(m + 1, n - m + 1, p) - log(n + 1)
22+
val = min(0, betalogpdf(m + 1, n - m + 1, p) - log(n + 1))
2323
return 0 <= k <= n && isinteger(k) ? val : oftype(val, -Inf)
2424
end

src/distrs/tdist.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tdistpdf(ν::Real, x::Real) = exp(tdistlogpdf(ν, x))
1717

1818
tdistlogpdf::Real, x::Real) = tdistlogpdf(promote(ν, x)...)
1919
function tdistlogpdf::T, x::T) where {T<:Real}
20+
isinf(ν) && return normlogpdf(x)
2021
νp12 =+ 1) / 2
2122
return loggamma(νp12) - (logπ + log(ν)) / 2 - loggamma/ 2) - νp12 * log1p(x^2 / ν)
2223
end

test/misc.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ end
6363
@test binomlogpdf(1, 0.5, prevfloat(1.0)) == -Inf
6464
@test binomlogpdf(1, 0.5, nextfloat(1.0)) == -Inf
6565
end
66+
67+
@testset "binom special cases" begin
68+
for (n, p, k) in ((5, 0.0, 0), (5, 1.0, 5))
69+
@test iszero(binomlogpdf(n, p, k))
70+
@test isone(binompdf(n, p, k))
71+
end
72+
end

test/rmath.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ end
301301
((1,), -5f0:0.1f0:5f0),
302302
((1,), -Float16(5):Float16(0.1):Float16(5)),
303303
((1,), -5//1:5//1),
304+
((Inf,), -5.0:0.1:5.0),
305+
((Inf32,), -5f0:0.1f0:5f0),
304306
])
305307

306308
rmathcomp_tests("srdist", [

0 commit comments

Comments
 (0)