Skip to content

Commit

Permalink
Make ChainRulesCore and InverseFunctions weak dependencies (#153)
Browse files Browse the repository at this point in the history
* Make ChainRulesCore and InverseFunctions weak dependencies

* Test Julia nightly to check weak dependencies

* Rename extensions
  • Loading branch information
devmotion authored Feb 28, 2023
1 parent 87a760a commit 56e1055
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- '1.3' # oldest supported version
- '1.6' # LTS
- '1' # latest release
- 'nightly'
os:
- ubuntu-latest
- macos-latest
Expand Down
14 changes: 12 additions & 2 deletions 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 = "1.2.1"
version = "1.3.0"

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

[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"

[extensions]
StatsFunsChainRulesCoreExt = "ChainRulesCore"
StatsFunsInverseFunctionsExt = "InverseFunctions"

[compat]
ChainRulesCore = "1"
HypergeometricFunctions = "0.3.10"
Expand All @@ -24,10 +32,12 @@ SpecialFunctions = "1.8.4, 2.1.4"
julia = "1.3"

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

[targets]
test = ["ChainRulesTestUtils", "ForwardDiff", "Random", "Test"]
test = ["ChainRulesCore", "ChainRulesTestUtils", "ForwardDiff", "InverseFunctions", "Random", "Test"]
8 changes: 8 additions & 0 deletions src/chainrules.jl → ext/StatsFunsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module StatsFunsChainRulesCoreExt

using StatsFuns
using StatsFuns: digamma
import ChainRulesCore

ChainRulesCore.@scalar_rule(
betalogpdf::Real, β::Real, x::Number),
@setup(z = digamma+ β)),
Expand Down Expand Up @@ -76,3 +82,5 @@ ChainRulesCore.@scalar_rule(
- x * b,
),
)

end # module
7 changes: 7 additions & 0 deletions src/inverse.jl → ext/StatsFunsInverseFunctionsExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module StatsFunsInverseFunctionsExt

using StatsFuns
import InverseFunctions

InverseFunctions.inverse(::typeof(normcdf)) = norminvcdf
InverseFunctions.inverse(::typeof(norminvcdf)) = normcdf

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

InverseFunctions.inverse(::typeof(normlogccdf)) = norminvlogccdf
InverseFunctions.inverse(::typeof(norminvlogccdf)) = normlogccdf

end # module
8 changes: 4 additions & 4 deletions src/StatsFuns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module StatsFuns
using Base: Math.@horner
using Reexport
using SpecialFunctions
import ChainRulesCore
import InverseFunctions

# reexports
@reexport using IrrationalConstants:
Expand Down Expand Up @@ -262,7 +260,9 @@ include(joinpath("distrs", "pois.jl"))
include(joinpath("distrs", "tdist.jl"))
include(joinpath("distrs", "srdist.jl"))

include("chainrules.jl")
include("inverse.jl")
if !isdefined(Base, :get_extension)
include("../ext/StatsFunsChainRulesCoreExt.jl")
include("../ext/StatsFunsInverseFunctionsExt.jl")
end

end # module

2 comments on commit 56e1055

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/78685

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.0 -m "<description of version>" 56e105541cf8fd5e7e8a8e145ef0eb83d823ce37
git push origin v1.3.0

Please sign in to comment.