Skip to content

Commit

Permalink
missing promotion (#394)
Browse files Browse the repository at this point in the history
* missing promotion

* promote before creating State structs
  • Loading branch information
jverzani authored Aug 12, 2023
1 parent 73ce5eb commit 385bbea
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 17 deletions.
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 = "2.0.17"
version = "2.0.18"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
6 changes: 3 additions & 3 deletions src/Bracketing/alefeld_potra_shi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ end
# set d, ee to a
function init_state(::AbstractAlefeldPotraShi, F, x₀, x₁, fx₀, fx₁; c=nothing, fc=nothing)
a, b, fa, fb = x₀, x₁, fx₀, fx₁
iszero(fa) && return AbstractAlefeldPotraShiState(b, a, a, a, fb, fa, fa, fa)
iszero(fb) && return AbstractAlefeldPotraShiState(b, a, a, a, fb, fa, fa, fa)
iszero(fa) && return AbstractAlefeldPotraShiState(promote(b, a, a, a)..., promote(fb, fa, fa, fa)...)
iszero(fb) && return AbstractAlefeldPotraShiState(promote(b, a, a, a)..., promote(fb, fa, fa, fa)...)

if a > b
a, b, fa, fb = b, a, fb, fa
Expand All @@ -59,7 +59,7 @@ function init_state(::AbstractAlefeldPotraShi, F, x₀, x₁, fx₀, fx₁; c=no
end

(iszero(fc) || !isfinite(fc)) &&
return AbstractAlefeldPotraShiState(c, a, a, a, fc, fa, fa, fa)
return AbstractAlefeldPotraShiState(promote(c, a, a, a)..., promote(fc, fa, fa, fa)...)

a, b, d, fa, fb, fd = bracket(a, b, c, fa, fb, fc)
assert_bracket(fa, fb)
Expand Down
4 changes: 2 additions & 2 deletions src/Bracketing/bisection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function init_state(
end

# handle interval if fa*fb ≥ 0 (explicit, but also not needed)
(iszero(fx₀) || iszero(fx₁)) && return UnivariateZeroState(x₁, x₀, fx₁, fx₀)
(iszero(fx₀) || iszero(fx₁)) && return UnivariateZeroState(promote(x₁, x₀)..., promote(fx₁, fx₀)...)
assert_bracket(fx₀, fx₁)
if sign(fm) * fx₀ < 0 * oneunit(fx₀)
a, b, fa, fb = x₀, m, fx₀, fm
Expand All @@ -57,7 +57,7 @@ function init_state(
# handles case where a=-0.0, b=1.0 without error
sign(a) * sign(b) < 0 && throw(ArgumentError("_middle error"))

UnivariateZeroState(b, a, fb, fa)
UnivariateZeroState(promote(b, a)..., promote(fb, fa)...)
end

const FloatNN = Union{Float64,Float32,Float16}
Expand Down
2 changes: 1 addition & 1 deletion src/Bracketing/bracketing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function init_state(M::AbstractBracketingMethod, F, x₀, x₁, fx₀, fx₁)
(iszero(fx₀) || iszero(fx₁)) && return UnivariateZeroState(x₁, x₀, fx₁, fx₀)
assert_bracket(fx₀, fx₁)
a, b, fa, fb = (x₀ < x₁) ? (x₀, x₁, fx₀, fx₁) : (x₁, x₀, fx₁, fx₀)
UnivariateZeroState(b, a, fb, fa)
UnivariateZeroState(promote(b, a)..., promote(fb, fa)...)
end

Base.last(state::AbstractUnivariateZeroState, M::AbstractBracketingMethod) =
Expand Down
4 changes: 2 additions & 2 deletions src/Bracketing/brent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ function init_state(::Brent, F, x₀, x₁, fx₀, fx₁)
end

# check if fu*fv ≥ 0
(iszero(fu) || iszero(fv)) && return BrentState(u, v, v, v, fu, fv, fv, true)
(iszero(fu) || iszero(fv)) && return BrentState(promote(u, v, v, v)..., promote(fu, fv, fv)..., true)
assert_bracket(fu, fv)

BrentState(u, v, v, v, fu, fv, fv, true)
BrentState(promote(u, v, v, v)..., promote(fu, fv, fv)..., true)
end

function update_state(
Expand Down
2 changes: 1 addition & 1 deletion src/Bracketing/chandrapatlu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
function init_state(::Chandrapatla, F, x₀, x₁, fx₀, fx₁)
a, b, fa, fb = x₁, x₀, fx₁, fx₀
c, fc = a, fa
ChandrapatlaState(a, b, c, fa, fb, fc)
ChandrapatlaState(promote(a, b, c)..., promote(fa, fb, fc)...)
end

function update_state(
Expand Down
4 changes: 2 additions & 2 deletions src/Bracketing/itp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ function init_state(M::ITP, F, x₀, x₁, fx₀, fx₁)
ϵ2n₁₂ = zero(float(x₁) / x₁) # ϵ*2^(ceil(Int, log2((b-a)/(2*ϵ))) + n₀)

# handle interval if fa*fb ≥ 0 (explicit, but also not needed)
(iszero(fx₀) || iszero(fx₁)) && return ITPState(x₁, x₀, fx₁, fx₀, 0, ϵ2n₁₂, x₁)
(iszero(fx₀) || iszero(fx₁)) && return ITPState(promote(x₁, x₀)..., promote(fx₁, fx₀)..., 0, ϵ2n₁₂, x₁)
assert_bracket(fx₀, fx₁)

a, b, fa, fb = x₀, x₁, fx₀, fx₁

ITPState(b, a, fb, fa, 0, ϵ2n₁₂, a)
ITPState(promote(b, a)..., promote(fb, fa)..., 0, ϵ2n₁₂, a)
end

function update_state(M::ITP, F, o::ITPState{T,S,R}, options, l=NullTracks()) where {T,S,R}
Expand Down
2 changes: 1 addition & 1 deletion src/Derivative/halley_like.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ end

function init_state(::AbstractHalleyLikeMethod, F, x₀::T, x₁::T, fx₀, fx₁) where {T}
fx₁, (Δ::T, ΔΔ::T) = F(x₁)
HalleyState(x₁, x₀, Δ, ΔΔ, fx₁, fx₀)
HalleyState(promote(x₁, x₀)..., Δ, ΔΔ, promote(fx₁, fx₀)...)
end

initial_fncalls(M::AbstractHalleyLikeMethod) = 2 * 3
Expand Down
2 changes: 1 addition & 1 deletion src/Derivative/newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ end
# compute fx₁, Δ
function init_state(::Newton, F, x₀::T, x₁::T, fx₀, fx₁) where {T}
fx₁, Δ::T = F(x₁)
NewtonState(x₁, x₀, Δ, fx₁, fx₀)
NewtonState(promote(x₁, x₀)..., Δ, promote(fx₁, fx₀)...)
end

initial_fncalls(M::Newton) = 2
Expand Down
2 changes: 1 addition & 1 deletion src/Derivative/thukralb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function init_state(
fx₁;
Δs=nothing,
) where {T}
ThukralBState(x₁, x₀, NTuple{fn_argout(M) - 1,T}(Δs), fx₁, fx₀)
ThukralBState(promote(x₁, x₀)..., NTuple{fn_argout(M) - 1,T}(Δs), promote(fx₁, fx₀)...)
end

function update_state(
Expand Down
2 changes: 1 addition & 1 deletion src/DerivativeFree/derivative_free.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

# initialize from xs, fxs
function init_state(::AbstractSecantMethod, F, x₀, x₁, fx₀, fx₁)
UnivariateZeroState(x₁, x₀, fx₁, fx₀)
UnivariateZeroState(promote(x₁, x₀)..., promote(fx₁, fx₀)...)
end

initial_fncalls(::AbstractSecantMethod) = 2
Expand Down
2 changes: 1 addition & 1 deletion src/DerivativeFree/king.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
function init_state(::Union{King,Order1B}, F, x₀, x₁, fx₀, fx₁)
fₛ₀ = F(x₀ - fx₀ * oneunit(x₀) / oneunit(fx₀))
G₀ = -fx₀^2 / (fₛ₀ - fx₀)
KingState(x₁, x₀, fx₁, fx₀, G₀)
KingState(promote(x₁, x₀)..., promote(fx₁, fx₀, G₀)...)
end
initial_fncalls(::Union{King,Order1B}) = 3

Expand Down

2 comments on commit 385bbea

@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/89505

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

git tag -a v2.0.18 -m "<description of version>" 385bbead769bf79e0d6ada4afb10a10d659ec26f
git push origin v2.0.18

Please sign in to comment.