Skip to content

Commit

Permalink
Reinstate support SVector
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolaru committed May 29, 2024
1 parent b55251b commit 6505bc4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/linear_eq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ function gauss_seidel_contractor!(x::AbstractArray, A::AbstractMatrix, b::Abstra
x
end

function gauss_elimination_interval(A::AbstractMatrix, b::AbstractArray ; precondition=true)
function gauss_elimination_interval(A0::AbstractMatrix, b0::AbstractArray ; precondition=true)
if precondition
A, b = preconditioner(A, b)
A0, b0 = preconditioner(A0, b0)
end

A = copy(A)
b = copy(b)
A = similar(A0)
A .= A0
b = similar(b0)
b .= b0
n = size(A, 1)

p = similar(b)
Expand Down
8 changes: 8 additions & 0 deletions src/region.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,13 @@ function bisect_region(X::AbstractVector, α)
return X1, X2
end

function bisect_region(X::SVector{N, T}, α) where {N, T}
i = argmax(diam.(X))
x1, x2 = bisect_region(X[i], α)
X1 = SVector{N, T}(k == i ? x1 : X[k] for k in 1:N)
X2 = SVector{N, T}(k == i ? x2 : X[k] for k in 1:N)
return X1, X2
end

istrivial(X::Interval) = decoration(X) <= trv
istrivial(X::AbstractVector) = any(istrivial.(X))
2 changes: 0 additions & 2 deletions test/roots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ function test_newtonlike(f, derivative, X, contractor, nsol, tol=1e-10)
@test sum(roots_dist.(rts, roots(f, X ; contractor, derivative))) < tol
end

newtonlike_methods = [Newton, Krawczyk]

@testset "1D roots" begin
# Default
rts = roots(sin, interval(-5, 5))
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ using IntervalRootFinding
using IntervalArithmetic.Symbols
using Test

newtonlike_methods = [Newton, Krawczyk]

include("roots.jl")
include("svectors.jl")
include("test_smiley.jl")
include("linear_eq.jl")

Expand Down
19 changes: 19 additions & 0 deletions test/svectors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@testset "Static vectors" begin
f(xx) = [xx[1]^2 - 1, xx[2]^2 - 2]
g(xx) = SVector(xx[1]^2 - 1, xx[2]^2 - 2)

X = [interval(-5, 5), interval(-5, 5)]
S = SVector(interval(-5, 5), interval(-5, 5))

@testset for contractor in newtonlike_methods
rts = roots(f, X ; contractor)
rts2 = roots(g, S ; contractor)

for (rt, rt2) in zip(rts, rts2)
@test isequal_interval(
root_region(rt),
root_region(rt2)
)
end
end
end

0 comments on commit 6505bc4

Please sign in to comment.