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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
ThickNumbersForwardDiffExt = "ForwardDiff"

[compat]
DifferentiationInterface = "0.6"
ForwardDiff = "0.10, 1"
LinearAlgebra = "1"
julia = "1.9"

[extras]
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ForwardDiff", "Test"]
test = ["DifferentiationInterface", "ForwardDiff", "Test"]
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ end
Base.abs2(x::Interval) = Interval(mig(x)^2, mag(x)^2)
Base.sqrt(x::Interval) = Interval(sqrt(loval(x)), sqrt(hival(x)))

Base.conj(x::Interval{T}) where T = Interval{T}(conj(x.lo), conj(x.hi)) # needed for Enzyme

end # module IntervalArith
39 changes: 39 additions & 0 deletions test/extensions/di.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using ThickNumbers
using DifferentiationInterface
using ForwardDiff

using Test

include(joinpath(dirname(@__DIR__), "setpath.jl"))

using IntervalArith

@testset "DifferentiationInterface" begin
@test isempty(detect_ambiguities(ThickNumbers))
@test isempty(detect_ambiguities(IntervalArith))

for backend in (AutoForwardDiff(), )
a, b = Interval(1, 2), Interval(0, 0.1)
f1(t) = a + t*b
f2(x) = a + abs2(x)/2

df1(t) = derivative(f1, backend, t)
df2(x) = derivative(f2, backend, x)
@test df1(0.5) ≐ b
@test df2(b) ⩪ b
ddf2(x) = derivative(df2, backend, x)
@test ddf2(b) ≐ 1

# abs
dabs(x) = derivative(abs, backend, x)
ddabs(x) = derivative(dabs, backend, x)
dddabs(x) = derivative(ddabs, backend, x)
@test dabs(Interval(1.0, 2.0)) === Interval(1.0, 1.0)
@test ddabs(Interval(1.0, 2.0)) === Interval(0.0, 0.0)
@test dddabs(Interval(1.0, 2.0)) === Interval(0.0, 0.0)
@test dabs(Interval(-1.0, 2.0)) === Interval(-1.0, 1.0)
@test ddabs(Interval(-1.0, 2.0)) === Interval(0.0, Inf)
abs3 = dddabs(Interval(-1.0, 2.0))
@test abs3 === Interval(-Inf, Inf) || isnan_tn(abs3)
end
end
1 change: 1 addition & 0 deletions test/extensions/runtests.jl
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include("forwarddiff.jl")
include("di.jl")
Loading