11# # Pushforward
22
3- DI. prepare_pushforward (f, :: AutoForwardEnzyme , x, dx) = NoPushforwardExtras ()
3+ DI. prepare_pushforward (f, :: AutoForwardOrNothingEnzyme , x, dx) = NoPushforwardExtras ()
44
55function DI. value_and_pushforward (
6- f, backend:: AutoForwardEnzyme , x, dx, :: NoPushforwardExtras
6+ f, backend:: AutoForwardOrNothingEnzyme , x, dx, :: NoPushforwardExtras
77)
88 dx_sametype = convert (typeof (x), dx)
9- y, new_dy = autodiff (backend. mode , f, Duplicated, Duplicated (x, dx_sametype))
9+ y, new_dy = autodiff (forward_mode ( backend) , f, Duplicated, Duplicated (x, dx_sametype))
1010 return y, new_dy
1111end
1212
13- function DI. pushforward (f, backend:: AutoForwardEnzyme , x, dx, :: NoPushforwardExtras )
13+ function DI. pushforward (
14+ f, backend:: AutoForwardOrNothingEnzyme , x, dx, :: NoPushforwardExtras
15+ )
1416 dx_sametype = convert (typeof (x), dx)
15- new_dy = only (autodiff (backend. mode, f, DuplicatedNoNeed, Duplicated (x, dx_sametype)))
17+ new_dy = only (
18+ autodiff (forward_mode (backend), f, DuplicatedNoNeed, Duplicated (x, dx_sametype))
19+ )
1620 return new_dy
1721end
1822
1923function DI. value_and_pushforward! (
20- f, dy, backend:: AutoForwardEnzyme , x, dx, extras:: NoPushforwardExtras
24+ f, dy, backend:: AutoForwardOrNothingEnzyme , x, dx, extras:: NoPushforwardExtras
2125)
2226 # dy cannot be passed anyway
2327 y, new_dy = DI. value_and_pushforward (f, backend, x, dx, extras)
2428 return y, copyto! (dy, new_dy)
2529end
2630
2731function DI. pushforward! (
28- f, dy, backend:: AutoForwardEnzyme , x, dx, extras:: NoPushforwardExtras
32+ f, dy, backend:: AutoForwardOrNothingEnzyme , x, dx, extras:: NoPushforwardExtras
2933)
3034 # dy cannot be passed anyway
3135 return copyto! (dy, DI. pushforward (f, backend, x, dx, extras))
4650function DI. gradient (
4751 f, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardGradientExtras{C}
4852) where {C}
49- grad_tup = gradient (backend. mode , f, x, Val {C} (); shadow= extras. shadow)
53+ grad_tup = gradient (forward_mode ( backend) , f, x, Val {C} (); shadow= extras. shadow)
5054 return reshape (collect (grad_tup), size (x))
5155end
5256
5963function DI. gradient! (
6064 f, grad, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardGradientExtras{C}
6165) where {C}
62- grad_tup = gradient (backend. mode , f, x, Val {C} (); shadow= extras. shadow)
66+ grad_tup = gradient (forward_mode ( backend) , f, x, Val {C} (); shadow= extras. shadow)
6367 return copyto! (grad, grad_tup)
6468end
6569
6670function DI. value_and_gradient! (
6771 f, grad, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardGradientExtras{C}
6872) where {C}
69- grad_tup = gradient (backend. mode , f, x, Val {C} (); shadow= extras. shadow)
73+ grad_tup = gradient (forward_mode ( backend) , f, x, Val {C} (); shadow= extras. shadow)
7074 return f (x), copyto! (grad, grad_tup)
7175end
7276
@@ -76,35 +80,43 @@ struct EnzymeForwardOneArgJacobianExtras{C,O}
7680 shadow:: O
7781end
7882
79- function DI. prepare_jacobian (f, :: AutoForwardEnzyme , x)
83+ function DI. prepare_jacobian (f, :: AutoForwardOrNothingEnzyme , x)
8084 C = pick_chunksize (length (x))
8185 shadow = chunkedonehot (x, Val (C))
8286 return EnzymeForwardOneArgJacobianExtras {C,typeof(shadow)} (shadow)
8387end
8488
8589function DI. jacobian (
86- f, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras{C}
90+ f, backend:: AutoForwardOrNothingEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras{C}
8791) where {C}
88- jac_wrongshape = jacobian (backend. mode , f, x, Val {C} (); shadow= extras. shadow)
92+ jac_wrongshape = jacobian (forward_mode ( backend) , f, x, Val {C} (); shadow= extras. shadow)
8993 nx = length (x)
9094 ny = length (jac_wrongshape) ÷ length (x)
9195 return reshape (jac_wrongshape, ny, nx)
9296end
9397
9498function DI. value_and_jacobian (
95- f, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras
99+ f, backend:: AutoForwardOrNothingEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras
96100)
97101 return f (x), DI. jacobian (f, backend, x, extras)
98102end
99103
100104function DI. jacobian! (
101- f, jac, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras
105+ f,
106+ jac,
107+ backend:: AutoForwardOrNothingEnzyme ,
108+ x,
109+ extras:: EnzymeForwardOneArgJacobianExtras ,
102110)
103111 return copyto! (jac, DI. jacobian (f, backend, x, extras))
104112end
105113
106114function DI. value_and_jacobian! (
107- f, jac, backend:: AutoForwardEnzyme , x, extras:: EnzymeForwardOneArgJacobianExtras
115+ f,
116+ jac,
117+ backend:: AutoForwardOrNothingEnzyme ,
118+ x,
119+ extras:: EnzymeForwardOneArgJacobianExtras ,
108120)
109121 y, new_jac = DI. value_and_jacobian (f, backend, x, extras)
110122 return y, copyto! (jac, new_jac)
0 commit comments