Skip to content
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

Ensure that binomlogpdf returns non-positive values, t distributions with infinite parameter are supported, and add integration tests #126

Merged
merged 6 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/IntegrationTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: IntegrationTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It runs integration tests. Currently only with Distributions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same action is eg used by ChainRulesCore, DiffRules, and many Turing and SciML packages.


on:
pull_request:
branches:
- master
push:
branches:
- master
tags: '*'

jobs:
test:
name: ${{ matrix.package.repo }}/${{ matrix.package.group }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: [1]
os: [ubuntu-latest]
package:
- {user: JuliaStats, repo: Distributions.jl}

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: x64
- uses: julia-actions/julia-buildpkg@latest
- name: Clone Downstream
uses: actions/checkout@v2
with:
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
path: downstream
- name: Load this and run the downstream tests
shell: julia --color=yes --project=downstream {0}
run: |
using Pkg
try
# force it to use this PR's version of the package
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
Pkg.update()
Pkg.test() # resolver may fail with test time deps
catch err
err isa Pkg.Resolve.ResolverError || rethrow()
# If we can't resolve that means this is incompatible by SemVer and this is fine
# It means we marked this as a breaking change, so we don't need to worry about
# Mistakenly introducing a breaking change, as we have intentionally made one
@info "Not compatible with this release. No problem." exception=err
exit(0) # Exit immediately, as a success
end
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "StatsFuns"
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
version = "0.9.11"
version = "0.9.12"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
2 changes: 1 addition & 1 deletion src/distrs/binom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ binompdf(n::Real, p::Real, k::Real) = exp(binomlogpdf(n, p, k))
binomlogpdf(n::Real, p::Real, k::Real) = binomlogpdf(promote(n, p, k)...)
function binomlogpdf(n::T, p::T, k::T) where {T<:Real}
m = clamp(k, 0, n)
val = betalogpdf(m + 1, n - m + 1, p) - log(n + 1)
val = min(0, betalogpdf(m + 1, n - m + 1, p) - log(n + 1))
return 0 <= k <= n && isinteger(k) ? val : oftype(val, -Inf)
end
1 change: 1 addition & 0 deletions src/distrs/tdist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tdistpdf(ν::Real, x::Real) = exp(tdistlogpdf(ν, x))

tdistlogpdf(ν::Real, x::Real) = tdistlogpdf(promote(ν, x)...)
function tdistlogpdf(ν::T, x::T) where {T<:Real}
isinf(ν) && return normlogpdf(x)
νp12 = (ν + 1) / 2
return loggamma(νp12) - (logπ + log(ν)) / 2 - loggamma(ν / 2) - νp12 * log1p(x^2 / ν)
end
7 changes: 7 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ end
@test binomlogpdf(1, 0.5, prevfloat(1.0)) == -Inf
@test binomlogpdf(1, 0.5, nextfloat(1.0)) == -Inf
end

@testset "binom special cases" begin
for (n, p, k) in ((5, 0.0, 0), (5, 1.0, 5))
@test iszero(binomlogpdf(n, p, k))
@test isone(binompdf(n, p, k))
end
end
2 changes: 2 additions & 0 deletions test/rmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ end
((1,), -5f0:0.1f0:5f0),
((1,), -Float16(5):Float16(0.1):Float16(5)),
((1,), -5//1:5//1),
((Inf,), -5.0:0.1:5.0),
((Inf32,), -5f0:0.1f0:5f0),
])

rmathcomp_tests("srdist", [
Expand Down