Skip to content

Commit d485d8c

Browse files
committed
Merge branch 'master' into dw/chainrules_gamma
2 parents bdd6243 + a48ba24 commit d485d8c

File tree

11 files changed

+586
-428
lines changed

11 files changed

+586
-428
lines changed

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
name = "SpecialFunctions"
22
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
3-
version = "1.3.1"
3+
version = "1.4.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
7+
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
78
OpenSpecFun_jll = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
89

910
[compat]
10-
ChainRulesCore = "0.9"
11-
ChainRulesTestUtils = "0.6.3"
11+
ChainRulesCore = "0.9.40"
12+
ChainRulesTestUtils = "0.6.8"
13+
LogExpFunctions = "0.2"
1214
OpenSpecFun_jll = "0.5"
1315
julia = "1.3"
1416

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Most of these functions were formerly part of Base in early versions of Julia.
77
CI (Linux, macOS, FreeBSD, Windows):
88
[![Travis](https://travis-ci.org/JuliaMath/SpecialFunctions.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/SpecialFunctions.jl)
99
[![CI](https://github.com/JuliaMath/SpecialFunctions.jl/workflows/CI/badge.svg)](https://github.com/JuliaMath/SpecialFunctions.jl/actions?query=workflow%3ACI)
10-
[![Coveralls](https://coveralls.io/repos/github/JuliaMath/SpecialFunctions.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaMath/SpecialFunctions.jl?branch=master)
10+
[![codecov](https://codecov.io/gh/JuliaMath/SpecialFunctions.jl/branch/master/graph/badge.svg?token=qIKzX2I5ZK)](https://codecov.io/gh/JuliaMath/SpecialFunctions.jl)
1111

1212
Documentation:
1313
[![Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMath.github.io/SpecialFunctions.jl/stable)

src/SpecialFunctions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module SpecialFunctions
22

33
import ChainRulesCore
4+
import LogExpFunctions
45

56
using OpenSpecFun_jll
67

src/beta_inc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ function beta_integrand(a::Float64,b::Float64,x::Float64,y::Float64,mu::Float64=
109109
lambda = a - (a+b)*x
110110
end
111111
e = -lambda/a
112-
u = abs(e) > 0.6 ? u = e - log(x/x0) : - log1pmx(e)
112+
u = abs(e) > 0.6 ? e - log(x/x0) : - LogExpFunctions.log1pmx(e)
113113
e = lambda/b
114-
v = abs(e) > 0.6 ? e - log(y/y0) : - log1pmx(e)
114+
v = abs(e) > 0.6 ? e - log(y/y0) : - LogExpFunctions.log1pmx(e)
115115
z = esum(mu, -(a*u + b*v))
116116
return (1.0/sqrt(2*pi))*sqrt(b*x0)*z*exp(-stirling_corr(a,b))
117117
elseif x > 0.375
@@ -271,7 +271,7 @@ function beta_inc_asymptotic_symmetric(a::Float64, b::Float64, lambda::Float64,
271271
r1 = (b-a)/b
272272
w0 = 1.0/sqrt(a*(1.0+h))
273273
end
274-
f = -a*log1pmx(-(lambda/a)) - b*log1pmx((lambda/b))
274+
f = -a*LogExpFunctions.log1pmx(-(lambda/a)) - b*LogExpFunctions.log1pmx(lambda/b)
275275
t = exp(-f)
276276
if t == 0.0
277277
return ans

src/chainrules.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const BESSEL_ORDER_INFO = """
2+
derivatives of Bessel functions with respect to the order are not implemented currently:
3+
https://github.com/JuliaMath/SpecialFunctions.jl/issues/160
4+
"""
5+
16
ChainRulesCore.@scalar_rule(airyai(x), airyaiprime(x))
27
ChainRulesCore.@scalar_rule(airyaiprime(x), x * airyai(x))
38
ChainRulesCore.@scalar_rule(airybi(x), airybiprime(x))
@@ -52,49 +57,49 @@ ChainRulesCore.@scalar_rule(trigamma(x), polygamma(2, x))
5257
ChainRulesCore.@scalar_rule(
5358
besselj(ν, x),
5459
(
55-
ChainRulesCore.@thunk(error("not implemented")),
60+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
5661
(besselj- 1, x) - besselj+ 1, x)) / 2
5762
),
5863
)
5964
ChainRulesCore.@scalar_rule(
6065
besseli(ν, x),
6166
(
62-
ChainRulesCore.@thunk(error("not implemented")),
67+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
6368
(besseli- 1, x) + besseli+ 1, x)) / 2,
6469
),
6570
)
6671
ChainRulesCore.@scalar_rule(
6772
bessely(ν, x),
6873
(
69-
ChainRulesCore.@thunk(error("not implemented")),
74+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
7075
(bessely- 1, x) - bessely+ 1, x)) / 2,
7176
),
7277
)
7378
ChainRulesCore.@scalar_rule(
7479
besselk(ν, x),
7580
(
76-
ChainRulesCore.@thunk(error("not implemented")),
81+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
7782
-(besselk- 1, x) + besselk+ 1, x)) / 2,
7883
),
7984
)
8085
ChainRulesCore.@scalar_rule(
8186
hankelh1(ν, x),
8287
(
83-
ChainRulesCore.@thunk(error("not implemented")),
88+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
8489
(hankelh1- 1, x) - hankelh1+ 1, x)) / 2,
8590
),
8691
)
8792
ChainRulesCore.@scalar_rule(
8893
hankelh2(ν, x),
8994
(
90-
ChainRulesCore.@thunk(error("not implemented")),
95+
ChainRulesCore.@not_implemented(BESSEL_ORDER_INFO),
9196
(hankelh2- 1, x) - hankelh2+ 1, x)) / 2,
9297
),
9398
)
9499
ChainRulesCore.@scalar_rule(
95100
polygamma(m, x),
96101
(
97-
ChainRulesCore.@thunk(error("not implemented")),
102+
ChainRulesCore.DoesNotExist(),
98103
polygamma(m + 1, x),
99104
),
100105
)

src/expint.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,19 @@ function En_cf_gamma(ν::Number, z::Number, n::Int=1000)
214214
ϵ = 10*eps(real(B))
215215
scale = sqrt(floatmax(real(A)))
216216

217-
iters = 1
218-
j = 1
219-
for i = 2:n
217+
iters = 0
218+
for i = 1:n
220219
iters += 1
221220

222-
term = iseven(i) ? -(i÷2 - 1 - ν)*z : z*(i÷2)
223-
A, Aprev = (i - ν)*A + term * Aprev, A
224-
B, Bprev = (i - ν)*B + term * Bprev, B
221+
a = iseven(i) ? (i÷2)*z : -((i + 1)÷2 - ν)*z
222+
b = (i + 1 - ν)
223+
224+
A, Aprev = b*A + a*Aprev, A
225+
B, Bprev = b*B + a*Bprev, B
225226

226-
conv = abs(Aprev*B - A*Bprev) < ϵ*abs(B*Bprev)
227-
conv && break
227+
if abs(Aprev*B - A*Bprev) < ϵ*abs(Aprev*B)
228+
break
229+
end
228230

229231
if max(abs(real(A)), abs(imag(A))) > scale
230232
A /= scale
@@ -436,6 +438,7 @@ function _expint(ν::Number, z::Number, niter::Int=1000, ::Val{expscaled}=Val{fa
436438
else
437439
g, cf, _ = zero(z), En_cf_nogamma(ν, z, niter)...
438440
end
441+
439442
g != 0 && (g *= gmult)
440443
cf = expscaled ? cf : En_safeexpmult(-z, cf)
441444
return g + cf

0 commit comments

Comments
 (0)