@@ -3,7 +3,7 @@ module DifferentiationInterfaceFiniteDifferencesExt
33using ADTypes: AutoFiniteDifferences
44import DifferentiationInterface as DI
55using FillArrays: OneElement
6- using FiniteDifferences: FiniteDifferences, jvp, j′vp
6+ using FiniteDifferences: FiniteDifferences, grad, jacobian, jvp, j′vp
77using LinearAlgebra: dot
88
99DI. supports_mutation (:: AutoFiniteDifferences ) = DI. MutationNotSupported ()
@@ -12,22 +12,62 @@ function FiniteDifferences.to_vec(a::OneElement) # TODO: remove type piracy (ht
1212 return FiniteDifferences. to_vec (collect (a))
1313end
1414
15- function DI. value_and_pushforward (
16- f, backend:: AutoFiniteDifferences{fdm} , x, dx, extras:: Nothing
17- ) where {fdm}
18- y = f (x)
19- return y, jvp (backend. fdm, f, (x, dx))
15+ # # Pushforward
16+
17+ function DI. pushforward (f, backend:: AutoFiniteDifferences , x, dx, extras:: Nothing )
18+ return jvp (backend. fdm, f, (x, dx))
19+ end
20+
21+ function DI. value_and_pushforward (f, backend:: AutoFiniteDifferences , x, dx, extras:: Nothing )
22+ return f (x), DI. pushforward (f, backend, x, dx, extras)
23+ end
24+
25+ # # Pullback
26+
27+ function DI. pullback (f, backend:: AutoFiniteDifferences , x, dy, extras:: Nothing )
28+ return only (j′vp (backend. fdm, f, dy, x))
2029end
2130
22- #=
23- # TODO : why does this fail?
31+ function DI. value_and_pullback (f, backend:: AutoFiniteDifferences , x, dy, extras:: Nothing )
32+ return f (x), DI. pullback (f, backend, x, dy, extras)
33+ end
34+
35+ # # Gradient
36+
37+ function DI. gradient (f, backend:: AutoFiniteDifferences , x, extras:: Nothing )
38+ return only (grad (backend. fdm, f, x))
39+ end
40+
41+ function DI. value_and_gradient (f, backend:: AutoFiniteDifferences , x, extras:: Nothing )
42+ return f (x), DI. gradient (f, backend, x, extras)
43+ end
44+
45+ function DI. gradient!! (f, grad, backend:: AutoFiniteDifferences , x, extras:: Nothing )
46+ return DI. gradient (f, backend, x, extras)
47+ end
48+
49+ function DI. value_and_gradient!! (
50+ f, grad, backend:: AutoFiniteDifferences , x, extras:: Nothing
51+ )
52+ return DI. value_and_gradient (f, backend, x)
53+ end
54+
55+ # # Jacobian
56+
57+ function DI. jacobian (f, backend:: AutoFiniteDifferences , x, extras:: Nothing )
58+ return only (jacobian (backend. fdm, f, x))
59+ end
60+
61+ function DI. value_and_jacobian (f, backend:: AutoFiniteDifferences , x, extras:: Nothing )
62+ return f (x), DI. jacobian (f, backend, x, extras)
63+ end
64+
65+ function DI. jacobian!! (f, jac, backend:: AutoFiniteDifferences , x, extras:: Nothing )
66+ return DI. jacobian (f, backend, x, extras)
67+ end
2468
25- function DI.value_and_pullback(
26- f, backend::AutoFiniteDifferences{fdm}, x, dy, extras::Nothing
27- ) where {fdm}
28- y = f(x)
29- return y, j′vp(backend.fdm, f, x, dy)[1]
69+ function DI. value_and_jacobian!! (f, jac, backend:: AutoFiniteDifferences , x, extras:: Nothing )
70+ return DI. value_and_jacobian (f, backend, x)
3071end
31- =#
3272
3373end
0 commit comments