Skip to content

Commit

Permalink
Set const to avoid type instability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Sep 12, 2024
1 parent 9158744 commit 210f656
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,27 +176,28 @@ Enzyme.autodiff(Reverse, f3, Duplicated(copy(A), dA), Duplicated(copy(b1), db1),
=#

A = rand(n, n);
const _A = rand(n, n);
dA = zeros(n, n);
b1 = rand(n);
const _b1 = rand(n);
for alg in (
LUFactorization(),
RFLUFactorization() # KrylovJL_GMRES(), fails
)
@show alg
function fb(b)
prob = LinearProblem(A, b)
prob = LinearProblem(_A, b)

sol1 = solve(prob, alg)

sum(sol1.u)
end
fb(b1)

fd_jac = FiniteDiff.finite_difference_jacobian(fb, b1) |> vec
fd_jac = FiniteDiff.finite_difference_jacobian(fb, _b1) |> vec
@show fd_jac

en_jac = map(onehot(b1)) do db1
eres = Enzyme.autodiff(Forward, fb, Duplicated(copy(b1), db1))
eres = Enzyme.autodiff(Forward, fb, Duplicated(copy(_b1), db1))
eres[1]
end |> collect
@show en_jac
Expand Down

0 comments on commit 210f656

Please sign in to comment.