Skip to content

Commit 51a0f1c

Browse files
authored
Make ChainRulesCore, ChangesOfVariables, and InverseFunctions weak dependencies (#62)
1 parent 59b8c09 commit 51a0f1c

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

Project.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LogExpFunctions"
22
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
33
authors = ["StatsFun.jl contributors, Tamas K. Papp <[email protected]>"]
4-
version = "0.3.19"
4+
version = "0.3.20"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
@@ -11,6 +11,16 @@ InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
1111
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
1212
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1313

14+
[weakdeps]
15+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
16+
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
17+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
18+
19+
[extensions]
20+
ChainRulesCoreExt = "ChainRulesCore"
21+
ChangesOfVariablesExt = "ChangesOfVariables"
22+
InverseFunctionsExt = "InverseFunctions"
23+
1424
[compat]
1525
ChainRulesCore = "1"
1626
ChangesOfVariables = "0.1"
@@ -20,12 +30,15 @@ IrrationalConstants = "0.1"
2030
julia = "1"
2131

2232
[extras]
33+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
2334
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
35+
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
2436
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2537
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
38+
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
2639
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
2740
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2841
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2942

3043
[targets]
31-
test = ["ChainRulesTestUtils", "FiniteDifferences", "ForwardDiff", "OffsetArrays", "Random", "Test"]
44+
test = ["ChainRulesCore", "ChainRulesTestUtils", "ChangesOfVariables", "FiniteDifferences", "ForwardDiff", "InverseFunctions", "OffsetArrays", "Random", "Test"]

src/chainrules.jl renamed to ext/ChainRulesCoreExt.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module ChainRulesCoreExt
2+
3+
using LogExpFunctions
4+
import ChainRulesCore
5+
6+
import LinearAlgebra
7+
18
function _Ω_∂_xlogx(x::Real)
29
logx = log(x)
310
y = x * logx
@@ -178,3 +185,5 @@ end
178185

179186
ChainRulesCore.@scalar_rule(cloglog(x), (-inv((1 - x) * log1p(-x)),))
180187
ChainRulesCore.@scalar_rule(cexpexp(x), (-xexpx(-exp(x)),))
188+
189+
end # module

src/with_logabsdet_jacobian.jl renamed to ext/ChangesOfVariablesExt.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module ChangesOfVariablesExt
2+
3+
using LogExpFunctions
4+
import ChangesOfVariables
5+
import IrrationalConstants
6+
17
function ChangesOfVariables.with_logabsdet_jacobian(::typeof(log1pexp), x::Real)
28
y = log1pexp(x)
39
return y, x - y
@@ -35,3 +41,5 @@ function ChangesOfVariables.with_logabsdet_jacobian(::typeof(logcosh), x::Real)
3541
y = abs_x + z - IrrationalConstants.logtwo
3642
return y, log1mexp(a) - z
3743
end
44+
45+
end # module

src/inverse.jl renamed to ext/InverseFunctionsExt.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
module InverseFunctionsExt
2+
3+
using LogExpFunctions
4+
import InverseFunctions
5+
16
InverseFunctions.inverse(::typeof(log1pexp)) = logexpm1
27
InverseFunctions.inverse(::typeof(logexpm1)) = log1pexp
38

@@ -10,3 +15,5 @@ InverseFunctions.inverse(::typeof(logistic)) = logit
1015

1116
InverseFunctions.inverse(::typeof(cloglog)) = cexpexp
1217
InverseFunctions.inverse(::typeof(cexpexp)) = cloglog
18+
19+
end # module

src/LogExpFunctions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ module LogExpFunctions
33
using DocStringExtensions: SIGNATURES
44
using Base: Math.@horner
55

6-
import ChainRulesCore
7-
import ChangesOfVariables
8-
import InverseFunctions
96
import IrrationalConstants
107
import LinearAlgebra
118

@@ -15,8 +12,11 @@ export xlogx, xlogy, xlog1py, xexpx, xexpy, logistic, logit, log1psq, log1pexp,
1512

1613
include("basicfuns.jl")
1714
include("logsumexp.jl")
18-
include("chainrules.jl")
19-
include("inverse.jl")
20-
include("with_logabsdet_jacobian.jl")
15+
16+
if !isdefined(Base, :get_extension)
17+
include("../ext/ChainRulesCoreExt.jl")
18+
include("../ext/ChangesOfVariablesExt.jl")
19+
include("../ext/InverseFunctionsExt.jl")
20+
end
2121

2222
end # module

0 commit comments

Comments
 (0)