Skip to content

Commit

Permalink
add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
agerlach committed Jun 14, 2023
1 parent eb2297f commit 12d5ca5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ad.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function _abs_deriv(x::Interval{T}) where T
if inf(x) == zero(T)
return Interval(one(T))
elseif sup(x) == zero(T)
return -one(T) .. one(T)
else
return sign(x)
end
end
14 changes: 14 additions & 0 deletions test/interval_tests/ad.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using IntervalArithmetic, ForwardDiff
using Test

@testset "AD" begin
@test ForwardDiff.derivative(abs, -2.0 .. 2.0) == -1.0 .. 1.0
@test ForwardDiff.derivative(abs, 1.0 .. 2.0) == 1.0 .. 1.0
@test ForwardDiff.derivative(abs, -2.0 .. -1.0) == -1.0 .. -1.0
@test ForwardDiff.derivative(abs, Interval(0.0)) == Interval(1.0)
@test ForwardDiff.derivative(abs, -2.0 .. 0.0) == -1.0 .. 1.0
@test ForwardDiff.derivative(abs, 0.0 .. 2.0) == Interval(1.0)

# Test proper handeling at abs(0)
@test ForwardDiff.hessian(t -> abs(t[1])^2, [Interval(0.0)])[1] == Interval(2.0)
end

0 comments on commit 12d5ca5

Please sign in to comment.