Skip to content

Commit 4fe57eb

Browse files
committed
newton(): defer to Roots.jl implementation
Note that we really do need `Roots.jl` 2.2.0-or-newer, because of JuliaMath/Roots.jl#445 This forces minimal Julia version to be 1.6
1 parent 96786f0 commit 4fe57eb

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
version:
26-
- '1.3'
26+
- '1.6'
2727
- '1'
2828
- pre
2929
os:
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
version: ${{ matrix.version }}
3838
# ARM64 on macos-latest is neither supported by older Julia versions nor setup-julia
39-
arch: ${{ matrix.os == 'macos-latest' && matrix.version != '1.3' && 'aarch64' || 'x64' }}
39+
arch: ${{ matrix.os == 'macos-latest' && matrix.version >= '1.8' && 'aarch64' || 'x64' }}
4040
show-versioninfo: true
4141
- uses: julia-actions/cache@v2
4242
- uses: julia-actions/julia-buildpkg@v1

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
1313
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1414
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
1515
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
16+
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
1617
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1718
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1819
StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
@@ -48,6 +49,7 @@ PDMats = "0.10, 0.11"
4849
Printf = "<0.0.1, 1"
4950
QuadGK = "2"
5051
Random = "<0.0.1, 1"
52+
Roots = "2.2"
5153
SparseArrays = "<0.0.1, 1"
5254
SpecialFunctions = "1.2, 2"
5355
StableRNGs = "1"
@@ -57,7 +59,7 @@ StatsAPI = "1.6"
5759
StatsBase = "0.32, 0.33, 0.34"
5860
StatsFuns = "0.9.15, 1"
5961
Test = "<0.0.1, 1"
60-
julia = "1.3"
62+
julia = "1.6"
6163

6264
[extras]
6365
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

src/quantilealgs.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Roots
2+
13
# Various algorithms for computing quantile
24

35
function quantile_bisect(d::ContinuousUnivariateDistribution, p::Real, lx::T, rx::T) where {T<:Real}
@@ -47,20 +49,8 @@ quantile_bisect(d::ContinuousUnivariateDistribution, p::Real) =
4749
# Distribution, with Application to the Inverse Gaussian Distribution
4850
# http://www.statsci.org/smyth/pubs/qinvgaussPreprint.pdf
4951

50-
function newton_impl(Δ, xs::T=mode(d), xrtol::Real=1e-12) where {T}
51-
x = xs - Δ(xs)
52-
@assert typeof(x) === T
53-
x0 = T(xs)
54-
while !isapprox(x, x0, atol=0, rtol=xrtol)
55-
x0 = x
56-
x = x0 - Δ(x0)
57-
end
58-
return x
59-
end
60-
6152
function newton((f,df), xs::T=mode(d), xrtol::Real=1e-12) where {T}
62-
Δ(x) = f(x)/df(x)
63-
return newton_impl(Δ, xs, xrtol)
53+
return find_zero((f,df), xs, Roots.Newton(), xatol=0, xrtol=xrtol, atol=0, rtol=eps(float(T)), maxiters=typemax(Int))
6454
end
6555

6656
function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), xrtol::Real=1e-12)

0 commit comments

Comments
 (0)