Skip to content

Commit a36c613

Browse files
authored
Remove test dependency on HypothesisTests (#1311)
1 parent 2b00d94 commit a36c613

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
3030
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
3131
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
3232
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
33-
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
3433
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
3534
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
3635
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
3736
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3837

3938
[targets]
40-
test = ["StableRNGs", "Calculus", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "StaticArrays", "HypothesisTests", "Test"]
39+
test = ["StableRNGs", "Calculus", "Distributed", "FiniteDifferences", "ForwardDiff", "JSON", "StaticArrays", "Test"]

test/matrixvariates.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ using Random
33
using LinearAlgebra
44
using PDMats
55
using Statistics
6-
using HypothesisTests
76
using Test
87
import JSON
98
import Distributions: _univariate, _multivariate, _rand_params
@@ -185,11 +184,26 @@ function test_against_univariate(D::MatrixDistribution, d::UnivariateDistributio
185184
nothing
186185
end
187186

187+
# Equivalent to `ExactOneSampleKSTest` in HypothesisTests.jl
188+
# We implement it here to avoid a circular dependency on HypothesisTests
189+
# that causes test failures when preparing a breaking release of Distributions
190+
function pvalue_kolmogorovsmirnoff(x::AbstractVector, d::UnivariateDistribution)
191+
# compute maximum absolute deviation from the empirical cdf
192+
n = length(x)
193+
cdfs = sort!(map(Base.Fix1(cdf, d), x))
194+
dmax = maximum(zip(cdfs, (0:(n-1))/n, (1:n)/n)) do (cdf, lower, upper)
195+
return max(cdf - lower, upper - cdf)
196+
end
197+
198+
# compute asymptotic p-value (see `KSDist`)
199+
return ccdf(KSDist(n), dmax)
200+
end
201+
188202
function test_draws_against_univariate_cdf(D::MatrixDistribution, d::UnivariateDistribution)
189203
α = 0.05
190204
M = 100000
191205
matvardraws = [rand(D)[1] for m in 1:M]
192-
@test pvalue(ExactOneSampleKSTest(matvardraws, d)) >= α
206+
@test pvalue_kolmogorovsmirnoff(matvardraws, d) >= α
193207
nothing
194208
end
195209

@@ -335,8 +349,7 @@ function test_special(dist::Type{Wishart})
335349
ρ = Chisq(ν)
336350
A = rand(q, M)
337351
z = [A[:, m]'*H[m]*A[:, m] / (A[:, m]'*Σ*A[:, m]) for m in 1:M]
338-
kstest = ExactOneSampleKSTest(z, ρ)
339-
@test pvalue(kstest) >= α
352+
@test pvalue_kolmogorovsmirnoff(z, ρ) >= α
340353
end
341354
@testset "H ~ W(ν, I) ⟹ H[i, i] ~ χ²(ν)" begin
342355
κ = n + 1
@@ -347,8 +360,7 @@ function test_special(dist::Type{Wishart})
347360
mymats[:, :, m] = rand(g)
348361
end
349362
for i in 1:n
350-
kstest = ExactOneSampleKSTest(mymats[i, i, :], ρ)
351-
@test pvalue(kstest) >= α / n
363+
@test pvalue_kolmogorovsmirnoff(mymats[i, i, :], ρ) >= α / n
352364
end
353365
end
354366
@testset "Check Singular Branch" begin
@@ -423,8 +435,7 @@ function test_special(dist::Type{LKJ})
423435
end
424436
for i in 1:d
425437
for j in 1:i-1
426-
kstest = ExactOneSampleKSTest(mymats[i, j, :], ρ)
427-
@test pvalue(kstest) >= α / L
438+
@test pvalue_kolmogorovsmirnoff(mymats[i, j, :], ρ) >= α / L
428439
end
429440
end
430441
end

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ using Random
66
using SpecialFunctions
77
using StatsBase
88
using LinearAlgebra
9-
using HypothesisTests
109

1110
import JSON
1211
import ForwardDiff

0 commit comments

Comments
 (0)