Skip to content

Commit 56e1055

Browse files
authored
Make ChainRulesCore and InverseFunctions weak dependencies (#153)
* Make ChainRulesCore and InverseFunctions weak dependencies * Test Julia nightly to check weak dependencies * Rename extensions
1 parent 87a760a commit 56e1055

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- '1.3' # oldest supported version
3030
- '1.6' # LTS
3131
- '1' # latest release
32+
- 'nightly'
3233
os:
3334
- ubuntu-latest
3435
- macos-latest

Project.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StatsFuns"
22
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
3-
version = "1.2.1"
3+
version = "1.3.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -12,6 +12,14 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1212
Rmath = "79098fc4-a85e-5d69-aa6a-4863f24498fa"
1313
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1414

15+
[weakdeps]
16+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
17+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
18+
19+
[extensions]
20+
StatsFunsChainRulesCoreExt = "ChainRulesCore"
21+
StatsFunsInverseFunctionsExt = "InverseFunctions"
22+
1523
[compat]
1624
ChainRulesCore = "1"
1725
HypergeometricFunctions = "0.3.10"
@@ -24,10 +32,12 @@ SpecialFunctions = "1.8.4, 2.1.4"
2432
julia = "1.3"
2533

2634
[extras]
35+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
2736
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
2837
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
38+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
2939
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3040
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3141

3242
[targets]
33-
test = ["ChainRulesTestUtils", "ForwardDiff", "Random", "Test"]
43+
test = ["ChainRulesCore", "ChainRulesTestUtils", "ForwardDiff", "InverseFunctions", "Random", "Test"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module StatsFunsChainRulesCoreExt
2+
3+
using StatsFuns
4+
using StatsFuns: digamma
5+
import ChainRulesCore
6+
17
ChainRulesCore.@scalar_rule(
28
betalogpdf::Real, β::Real, x::Number),
39
@setup(z = digamma+ β)),
@@ -76,3 +82,5 @@ ChainRulesCore.@scalar_rule(
7682
- x * b,
7783
),
7884
)
85+
86+
end # module
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module StatsFunsInverseFunctionsExt
2+
3+
using StatsFuns
4+
import InverseFunctions
5+
16
InverseFunctions.inverse(::typeof(normcdf)) = norminvcdf
27
InverseFunctions.inverse(::typeof(norminvcdf)) = normcdf
38

@@ -9,3 +14,5 @@ InverseFunctions.inverse(::typeof(norminvlogcdf)) = normlogcdf
914

1015
InverseFunctions.inverse(::typeof(normlogccdf)) = norminvlogccdf
1116
InverseFunctions.inverse(::typeof(norminvlogccdf)) = normlogccdf
17+
18+
end # module

src/StatsFuns.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module StatsFuns
33
using Base: Math.@horner
44
using Reexport
55
using SpecialFunctions
6-
import ChainRulesCore
7-
import InverseFunctions
86

97
# reexports
108
@reexport using IrrationalConstants:
@@ -262,7 +260,9 @@ include(joinpath("distrs", "pois.jl"))
262260
include(joinpath("distrs", "tdist.jl"))
263261
include(joinpath("distrs", "srdist.jl"))
264262

265-
include("chainrules.jl")
266-
include("inverse.jl")
263+
if !isdefined(Base, :get_extension)
264+
include("../ext/StatsFunsChainRulesCoreExt.jl")
265+
include("../ext/StatsFunsInverseFunctionsExt.jl")
266+
end
267267

268268
end # module

0 commit comments

Comments
 (0)