Skip to content

Commit 99a9551

Browse files
committed
Test for forward mode jacobians
1 parent 9faf189 commit 99a9551

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/autodiff.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ end
102102
@test res[1] ones(2, 2)
103103
end
104104

105+
f_sincos(x) = map(sin, x) + map(cos, reverse(x))
106+
f_sincos_jac(x) = [cos(x[i]) * (i == j ? 1 : 0) - sin(x[end-i+1]) * (i == (length(x) - j + 1) ? 1 : 0) for i in 1:length(x), j in 1:length(x)]
107+
108+
@testset "Forward Jacobian" begin
109+
jac(x) = only(Enzyme.jacobian(Enzyme.Forward, f_sincos, x))
110+
x_r = Reactant.to_rarray(rand(10))
111+
112+
j_gt = f_sincos_jac(x_r)
113+
j_reactant = Reactant.@jit jac(x_r)
114+
115+
@test j_reactant j_gt
116+
end
117+
105118
mutable struct StateReturn
106119
st::Any
107120
end

0 commit comments

Comments
 (0)