Skip to content

Commit

Permalink
Close Issue #423 (#424)
Browse files Browse the repository at this point in the history
* use typed NaN

* add test

* version bump
  • Loading branch information
jverzani authored Mar 13, 2024
1 parent d528e90 commit 9967bce
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 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.1.3"
version = "2.1.4"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
6 changes: 3 additions & 3 deletions src/convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ When the algorithm terminates, this function decides the stopped value or return
function decide_convergence(
M::AbstractNonBracketingMethod,
F,
state::AbstractUnivariateZeroState,
state::AbstractUnivariateZeroState{T,S},
options,
val,
)
) where {T, S}
xn0, xn1 = state.xn0, state.xn1
fxn1 = state.fxn1
val (:f_converged, :exact_zero, :converged) && return xn1
Expand All @@ -303,7 +303,7 @@ function decide_convergence(
end
end

NaN * xn1
nan(T) * xn1
end

# assumes stopped = :x_converged
Expand Down
2 changes: 1 addition & 1 deletion src/hybrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function solve!(
quad_ctr = 0
flag = :not_converged
ctr = 0
α = NaN * state.xn1
α = nan(typeof(state.xn1)) * state.xn1
while true
ctr += 1
flag, converged = assess_convergence(M, state, options)
Expand Down
5 changes: 5 additions & 0 deletions test/test_allocations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ import BenchmarkTools
@test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M, $p)) == 0
@test BenchmarkTools.@ballocated(solve(ZeroProblem($f, $x0), $M; p=$p)) == 0
end

# issue #423 type instability
for M in Ms
@test @inferred solve(ZeroProblem(sin, 3.0f0)) pi
end
end

@testset "simple: zero allocations" begin
Expand Down

2 comments on commit 9967bce

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.1.4 -m "<description of version>" 9967bce1e2eb850a4d13806a75103894523714e9
git push origin v2.1.4

Please sign in to comment.