Skip to content

Commit

Permalink
more work on 173 with AlefeldPotraShi (#174)
Browse files Browse the repository at this point in the history
* more work on 173 with AlefeldPotraShi

* bump CI to include 1.4
  • Loading branch information
jverzani authored Mar 23, 2020
1 parent a6dc315 commit 069d55f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ julia:
- 1.1
- 1.2
- 1.3
- 1.4
- nightly
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Roots"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "1.0.0"
version = "1.0.1"

[deps]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ environment:
- julia_version: 1.1
- julia_version: 1.2
- julia_version: 1.3
- julia_version: 1.4
- julia_version: latest

platform:
Expand Down
52 changes: 41 additions & 11 deletions src/bracketing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,16 @@ end
function check_zero(::AbstractBracketing, state, c, fc)
if isnan(c)
state.stopped = true
state.xn1 = c
#state.xn1 = c
state.xstar = c
state.fxstar =fc
state.message *= "NaN encountered. "
return true
elseif isinf(c)
state.stopped = true
state.xn1 = c
#state.xn1 = c
state.xstar = c
state.fxstar =fc
state.message *= "Inf encountered. "
return true
elseif iszero(fc)
Expand All @@ -561,9 +565,9 @@ end
function assess_convergence(method::AbstractAlefeldPotraShi, state::UnivariateZeroState{T,S}, options) where {T,S}

if state.stopped || state.x_converged || state.f_converged
if isnan(state.xstar)
state.xstar, state.fxstar = state.xn1, state.fxn1
end
## if isnan(state.xstar)
## state.xstar, state.fxstar = state.xn1, state.fxn1
## end
return true
end

Expand All @@ -581,7 +585,7 @@ function assess_convergence(method::AbstractAlefeldPotraShi, state::UnivariateZe

# check f
u,fu = choose_smallest(state.xn0, state.xn1, state.fxn0, state.fxn1)
u, fu = choose_smallest(u, state.m[1], fu, state.fm[1])
#u,fu = choose_smallest(u, state.m[1], fu, state.fm[1])

if abs(fu) <= maximum(promote(options.abstol, abs(u) * oneunit(fu) / oneunit(u) * options.reltol))
state.f_converged = true
Expand Down Expand Up @@ -638,15 +642,23 @@ function update_state(M::A42, f, state::UnivariateZeroState{T,S}, options::Univa
end
fc::S = f(c)
incfn(state)
check_zero(M, state, c, fc) && return nothing
if check_zero(M, state, c, fc)
return nothing
end

ab::T, bb::T, db::T, fab::S, fbb::S, fdb::S = bracket(a,b,c,fa,fb,fc)
eb::T, feb::S = d, fd

cb::T = take_a42_step(ab, bb, db, eb, fab, fbb, fdb, feb, delta)
fcb::S = f(cb)
incfn(state)
check_zero(M, state, cb, fcb) && return nothing
if check_zero(M, state, cb, fcb)
# tighten up bracket
state.xn0, state.xn1, state.m[1] = ab, bb, db
state.fxn0, state.fxn1, state.fm[1]= fab, fbb, fdb

return nothing
end

ab,bb,db,fab,fbb,fdb = bracket(ab,bb,cb,fab,fbb,fcb)

Expand All @@ -659,7 +671,13 @@ function update_state(M::A42, f, state::UnivariateZeroState{T,S}, options::Univa
end
fch::S = f(cb)
incfn(state)
check_zero(M, state, ch, fch) && return nothing
if check_zero(M, state, ch, fch)
# tighten up bracket
state.xn0, state.xn1, state.m[1] = ab, bb, db
state.fxn0, state.fxn1, state.fm[1]= fab, fbb, fdb

return nothing
end

ah::T, bh::T, dh::T, fah::S, fbh::S, fdh::S = bracket(ab, bb, ch, fab, fbb, fch)

Expand Down Expand Up @@ -714,7 +732,13 @@ function update_state(M::AlefeldPotraShi, f, state::UnivariateZeroState{T,S}, op
c = newton_quadratic(a,b,d,fa,fb,fd, 3, delta)
fc = f(c)
incfn(state)
check_zero(M, state, c, fc) && return nothing
if check_zero(M, state, c, fc)
# tighten up bracket
state.xn0, state.xn1, state.m[1] = a, b, d
state.fxn0, state.fxn1, state.fm[1]= fa, fb, fd

return nothing
end

a, b, d, fa, fb, fd = bracket(a, b, c, fa, fb,fc)

Expand All @@ -725,7 +749,13 @@ function update_state(M::AlefeldPotraShi, f, state::UnivariateZeroState{T,S}, op
end
fc = f(c)
incfn(state)
check_zero(M, state, c, fc) && return nothing
if check_zero(M, state, c, fc)
# tighten up bracket
state.xn0, state.xn1, state.m[1] = a, b, d
state.fxn0, state.fxn1, state.fm[1]= fa, fb, fd

return nothing
end

ahat::T, bhat::T, dhat::T, fahat::S, fbhat::S, fdhat::S = bracket(a, b, c, fa, fb, fc)
if bhat - ahat < μ * (b - a)
Expand Down

2 comments on commit 069d55f

@jverzani
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/11411

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.1 -m "<description of version>" 069d55f4d30609696f6bb3e5fbf6eaa9541a1dfe
git push origin v1.0.1

Please sign in to comment.