Skip to content

Commit

Permalink
Add more ForwardDiff related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Dec 2, 2023
1 parent 6a8f853 commit 8a854e2
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,31 @@ end
@test all(ForwardDiff.gradient( v -> g(v[1]), [interval(-1, 1)]) .=== [interval(convert(Interval{Float64}, -2), convert(Interval{Float64}, 2), trv)])
@test_broken all(ForwardDiff.hessian( v -> g(v[1]), [interval( 0 )]) .=== [interval(convert(Interval{Float64}, -2), convert(Interval{Float64}, 2), trv)])
end

@testset "sin" begin
x, y, w = interval(2), interval(-0.5, 0.5)
ϕ(t) = sin(x + (1+t)*w)
ϕ′(t) = cos(x + (1+t)*w) * w
ϕ′′(t) = -sin(x + (1+t)*w) * w * w
ϕ′′′(t) = -cos(x + (1+t)*w) * w * w * w
(t) = ForwardDiff.derivative(ϕ, t)
ddϕ(t) = ForwardDiff.derivative(dϕ, t)
dddϕ(t) = ForwardDiff.derivative(ddϕ, t)

@test ϕ′(0) === (0)
@test ϕ′′(0) === ddϕ(0)
@test ϕ′′′(0) === dddϕ(0)

y = interval(1)
ψ(t) = sin(x + (y+t)*w)
ψ′(t) = cos(x + (y+t)*w) * w
ψ′′(t) = -sin(x + (y+t)*w) * w * w
ψ′′′(t) = -cos(x + (y+t)*w) * w * w * w
(t) = ForwardDiff.derivative(ψ, t)
ddψ(t) = ForwardDiff.derivative(dψ, t)
dddψ(t) = ForwardDiff.derivative(ddψ, t)
@test ψ′(0) === (0)
@test_broken ψ′′(0) === ddψ(0)
@test_broken ψ′′′(0) === dddψ(0)
end
end

0 comments on commit 8a854e2

Please sign in to comment.