Skip to content

Commit

Permalink
fix issue with measurements (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverzani authored Dec 29, 2024
1 parent 18354b0 commit 9646748
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CommonSolve = "0.1, 0.2"
ForwardDiff = "0.10"
IntervalRootFinding = "0.5, 0.6"
JSON = "0.21"
Measurements = "2.11"
Polynomials = "1,2,3,4"
Printf = "<0.0.1, 1"
SpecialFunctions = "1,2"
Expand All @@ -50,6 +51,7 @@ ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand All @@ -60,4 +62,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "ChainRulesTestUtils", "JSON", "SpecialFunctions", "Statistics", "Test", "BenchmarkTools", "ForwardDiff", "Polynomials", "Unitful", "Zygote"]
test = ["Aqua", "ChainRulesTestUtils", "JSON", "SpecialFunctions", "Statistics", "Test", "BenchmarkTools", "ForwardDiff", "Measurements", "Polynomials", "Unitful", "Zygote"]
6 changes: 5 additions & 1 deletion src/Bracketing/alefeld_potra_shi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function update_state(
options,
l=NullTracks(),
) where {T,S}

atol, rtol = options.xabstol, options.xreltol
μ, λ = oftype(rtol, 0.5), oftype(rtol, 0.7)
tols = (; λ=λ, atol=atol, rtol=rtol)
Expand Down Expand Up @@ -144,7 +145,10 @@ function update_state(

ā, b̄, d, fā, fb̄, fd = bracket(a, b, x, fa, fb, fx)

if iszero(fx) || (b̄ - ā) <= tolₑ(ā, b̄, fā, fb̄, atol, rtol)

if ((b̄ - ā) <= tolₑ(ā, b̄, fā, fb̄, atol, rtol) ||
iszero(fx) || # exact zero
!isbracket(fā,fb̄)) # catch non bracket?, issue #453
@reset o.xn0 =
@reset o.xn1 =
@reset o.fxn0 = fā
Expand Down
15 changes: 15 additions & 0 deletions test/test_composable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Test
using Unitful
using Polynomials
using ForwardDiff
using Measurements

@testset "Test composability with other packages" begin
orders = [
Expand Down Expand Up @@ -82,4 +83,18 @@ using ForwardDiff
α = find_zero(D(h), (0, 1)) # find lowest point on loop
@test h(α) h+ 0.1)
@test h(α) h- 0.1)


# Measurements # issue #453
@testset "Measurements.jl" begin
a = measurement(1.0 , 0.1)
b = measurement(-3.0 , 0.1)
c = measurement(-10.0, 0.1)
f(x) = a*x^2 + b*x + c
x₀ = (measurement(-3.0, 0.1), measurement(0.0, 0.1))
for M (A42(), AlefeldPotraShi(), Bisection())
@test find_zero(f,x₀, M) -2.0
end
@test find_zero(f, measurement(0.0, 0.1)) -2.0
end
end

2 comments on commit 9646748

@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.

Error while trying to register: Version 2.2.2 already exists

Please sign in to comment.