Skip to content

Commit 165afcd

Browse files
author
Roger-luo
committed
add to_vec fallback
1 parent dd50a79 commit 165afcd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/grad.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function grad(fdm, f, d::Dict{K, V}) where {K, V}
3737
return dd
3838
end
3939

40+
function grad(fdm, f, x)
41+
v, back = to_vec(x)
42+
return back(grad(fdm, x->f(back(v)), v))
43+
end
44+
4045
function grad(fdm, f, xs...)
4146
return ntuple(length(xs)) do k
4247
grad(fdm, x->f(replace_arg(x, xs, k)...), xs[k])

0 commit comments

Comments
 (0)