Skip to content

Commit 5f0a078

Browse files
authored
Add differentials for exponential integrals (#328)
1 parent 66eb6c7 commit 5f0a078

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/chainrules.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ implemented currently:
99
https://github.com/JuliaMath/SpecialFunctions.jl/issues/317
1010
"""
1111

12+
const INCOMPLETE_EXPINT_INFO = """
13+
derivatives of the exponential integral with respect to parameter `ν` are not implemented
14+
currently:
15+
https://github.com/JuliaMath/SpecialFunctions.jl/issues/321
16+
"""
17+
1218
ChainRulesCore.@scalar_rule(airyai(x), airyaiprime(x))
1319
ChainRulesCore.@scalar_rule(airyaiprime(x), x * airyai(x))
1420
ChainRulesCore.@scalar_rule(airybi(x), airybiprime(x))
@@ -136,3 +142,24 @@ ChainRulesCore.@scalar_rule(
136142
-exp(- (x + Ω)) * x^(a - 1),
137143
)
138144
)
145+
146+
# exponential integrals
147+
ChainRulesCore.@scalar_rule(expint(z), - exp(-z) / z)
148+
ChainRulesCore.@scalar_rule(
149+
expint(ν, z),
150+
(
151+
ChainRulesCore.@not_implemented(INCOMPLETE_EXPINT_INFO),
152+
- expint- 1, z),
153+
)
154+
)
155+
ChainRulesCore.@scalar_rule(expintx(z), Ω - inv(z))
156+
ChainRulesCore.@scalar_rule(
157+
expintx(ν, z),
158+
(
159+
ChainRulesCore.@not_implemented(INCOMPLETE_EXPINT_INFO),
160+
Ω - expintx- 1, z),
161+
)
162+
)
163+
ChainRulesCore.@scalar_rule(expinti(x), exp(x) / x)
164+
ChainRulesCore.@scalar_rule(sinint(x), sinc(x / π))
165+
ChainRulesCore.@scalar_rule(cosint(x), cos(x) / x)

test/chainrules.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,27 @@
110110
end
111111
end
112112
end
113+
114+
@testset "exponential integrals" begin
115+
for x in (1.5, 2.5, 10.5, 1.6 + 1.6im, 1.6 - 1.6im, -4.6 + 1.6im)
116+
test_scalar(expint, x)
117+
test_scalar(expintx, x)
118+
119+
for nu in (-1.5, 2.2, 4.0)
120+
# ensure all complex if any complex for FiniteDifferences
121+
_x, _nu = promote(x, nu)
122+
123+
test_frule(expint, _nu, _x)
124+
test_rrule(expint, _nu, _x)
125+
126+
test_frule(expintx, _nu, _x)
127+
test_rrule(expintx, _nu, _x)
128+
end
129+
130+
isreal(x) || continue
131+
test_scalar(expinti, x)
132+
test_scalar(sinint, x)
133+
test_scalar(cosint, x)
134+
end
135+
end
113136
end

0 commit comments

Comments
 (0)