Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
exclude:
- os: macOS-latest
arch: x86
- os: windows-latest
arch: x86
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
Expand Down
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.6.3"
[deps]
BranchAndPrune = "d3bc4f2e-91e6-11e9-365e-cd067da536ce"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Expand All @@ -13,6 +14,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[compat]
BranchAndPrune = "0.2.1"
ForwardDiff = "0.10, 1"
InteractiveUtils = "1.10.0"
IntervalArithmetic = "1.0.3"
Reexport = "1"
StaticArrays = "1"
Expand Down
6 changes: 3 additions & 3 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ S = SUITE["Smiley"] = BenchmarkGroup()
for example in (SmileyExample22, SmileyExample52, SmileyExample54) #, SmileyExample55)
s = S[example.title] = BenchmarkGroup()
for contractor in (Newton, Krawczyk)
s[string(contractor)] = @benchmarkable roots($(example.f), $(example.region) ; contractor = $contractor, abstol = $tol)
s[string(contractor)] = @benchmarkable roots($(example.f), $(example.region) ; contractor = $contractor, abstol = $tol, infer_root_type = false)
end
end

Expand All @@ -39,7 +39,7 @@ L = 5.0
X = SVector(interval(-L, (L+1)), interval(-L, (L+1)))

for contractor in (Newton, Krawczyk)
S[string(contractor)] = @benchmarkable roots($(∇f), $X ; contractor = $contractor, abstol = 1e-5)
S[string(contractor)] = @benchmarkable roots($(∇f), $X ; contractor = $contractor, abstol = 1e-5, infer_root_type = false)
end


Expand All @@ -66,7 +66,7 @@ for (k, dr) in enumerate(dr_functions)

if k != 8 # dr8 is excluded as it has too many roots
for contractor in (Newton, Krawczyk)
s[string(contractor)] = @benchmarkable roots($dr, $X ; contractor = $contractor, abstol = $tol)
s[string(contractor)] = @benchmarkable roots($dr, $X ; contractor = $contractor, abstol = $tol, infer_root_type = false)
end
end
end
63 changes: 0 additions & 63 deletions perf/linear_eq.jl

This file was deleted.

149 changes: 0 additions & 149 deletions perf/linear_eq_results.txt

This file was deleted.

49 changes: 0 additions & 49 deletions perf/linear_eq_tabular.txt

This file was deleted.

66 changes: 0 additions & 66 deletions perf/slopes.jl

This file was deleted.

37 changes: 0 additions & 37 deletions perf/slopes_tabular.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/IntervalRootFinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using IntervalArithmetic.Symbols
using BranchAndPrune
using ForwardDiff
using ForwardDiff: derivative, jacobian
using InteractiveUtils
using StaticArrays

using LinearAlgebra
Expand Down
19 changes: 17 additions & 2 deletions src/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The returned `RootProblem` is an iterator that give access to the internal
state of the search during the iteration,
allowing to add callbacks and logging to the search.

Parameters
Keyword parameters
==========
- `contractor`: Contractor used to determine the status of a region.
Must be either `Newton`, `Krawczyk`, or `Bisection`. `Bisection` do not require
Expand All @@ -46,6 +46,11 @@ Parameters
Default: `0.0`.
- `max_iteration`: The maximum number of iteration, which also corresponds to
the maximum number of bisections allowed. Default: `100_000`.
- `infer_root_type`: When true, use the return type of the function as
type for the region in the returned roots, avoiding extra conversions
during the computation.
Otherwise, use the type of the provided region.
Default: `true`. Always `false` if the initial region is given as a `Root`.
- `where_bisect`: Value used to bisect the region. It is used to avoid
bisecting exactly on zero when starting with symmetrical regions,
often leading to having a solution directly on the boundary of a region,
Expand All @@ -55,7 +60,17 @@ Parameters
further.
Default: `[IntervalArithmetic.InconclusiveBooleanOperation]`.
"""
RootProblem(f, region ; kwargs...) = RootProblem(f, Root(region, :unkown) ; kwargs...)
function RootProblem(f, region ; infer_root_type = true, kwargs...)
if infer_root_type
T = last(InteractiveUtils.@code_typed(f(region)))
if isconcretetype(T)
region = convert(T, region)
else
@warn "Could not infer the return type of the function (it may be type instable). Got $T"
end
end
RootProblem(f, Root(region, :unkown) ; kwargs...)
end

function RootProblem(
f, root::Root ;
Expand Down
Loading
Loading