@@ -10,8 +10,10 @@ namespace Tensorflow.Gradients
1010 /// <summary>
1111 /// Gradients for operators defined in math_ops.py.
1212 /// </summary>
13+ [ RegisterGradient ( "math_grad" ) ]
1314 public class math_grad
1415 {
16+ [ RegisterGradient ( "Add" ) ]
1517 public static Tensor [ ] _AddGrad ( Operation op , Tensor [ ] grads )
1618 {
1719 var x = op . inputs [ 0 ] ;
@@ -32,6 +34,7 @@ public static Tensor[] _AddGrad(Operation op, Tensor[] grads)
3234 return new Tensor [ ] { r1 , r2 } ;
3335 }
3436
37+ [ RegisterGradient ( "DivNoNan" ) ]
3538 public static Tensor [ ] _DivNoNanGrad ( Operation op , Tensor [ ] grads )
3639 {
3740 var grad = grads [ 0 ] ;
@@ -59,6 +62,7 @@ public static Tensor[] _DivNoNanGrad(Operation op, Tensor[] grads)
5962 /// <param name="op"></param>
6063 /// <param name="grads"></param>
6164 /// <returns></returns>
65+ [ RegisterGradient ( "Exp" ) ]
6266 public static Tensor [ ] _ExpGrad ( Operation op , Tensor [ ] grads )
6367 {
6468 var grad = grads [ 0 ] ;
@@ -69,11 +73,13 @@ public static Tensor[] _ExpGrad(Operation op, Tensor[] grads)
6973 } ) ;
7074 }
7175
76+ [ RegisterGradient ( "Identity" ) ]
7277 public static Tensor [ ] _IdGrad ( Operation op , Tensor [ ] grads )
7378 {
7479 return new Tensor [ ] { grads [ 0 ] } ;
7580 }
7681
82+ [ RegisterGradient ( "Log" ) ]
7783 public static Tensor [ ] _LogGrad ( Operation op , Tensor [ ] grads )
7884 {
7985 var grad = grads [ 0 ] ;
@@ -84,6 +90,7 @@ public static Tensor[] _LogGrad(Operation op, Tensor[] grads)
8490 } ) ;
8591 }
8692
93+ [ RegisterGradient ( "Mul" ) ]
8794 public static Tensor [ ] _MulGrad ( Operation op , Tensor [ ] grads )
8895 {
8996 var x = op . inputs [ 0 ] ;
@@ -112,6 +119,7 @@ public static Tensor[] _MulGrad(Operation op, Tensor[] grads)
112119 return new Tensor [ ] { reshape1 , reshape2 } ;
113120 }
114121
122+ [ RegisterGradient ( "MatMul" ) ]
115123 public static Tensor [ ] _MatMulGrad ( Operation op , Tensor [ ] grads )
116124 {
117125 var grad = grads [ 0 ] ;
@@ -145,6 +153,7 @@ public static Tensor[] _MatMulGrad(Operation op, Tensor[] grads)
145153 return new Tensor [ ] { grad_a , grad_b } ;
146154 }
147155
156+ [ RegisterGradient ( "Mean" ) ]
148157 public static Tensor [ ] _MeanGrad ( Operation op , Tensor [ ] grads )
149158 {
150159 var grad = grads [ 0 ] ;
@@ -159,6 +168,7 @@ public static Tensor[] _MeanGrad(Operation op, Tensor[] grads)
159168 return new Tensor [ ] { math_ops . truediv ( sum_grad , math_ops . cast ( factor , sum_grad . dtype ) ) , null } ;
160169 }
161170
171+ [ RegisterGradient ( "Neg" ) ]
162172 public static Tensor [ ] _NegGrad ( Operation op , Tensor [ ] grads )
163173 {
164174 return new Tensor [ ] { - grads [ 0 ] } ;
@@ -169,6 +179,7 @@ private static Tensor _safe_shape_div(Tensor x, Tensor y)
169179 return math_ops . floordiv ( x , gen_math_ops . maximum ( y , 1 ) ) ;
170180 }
171181
182+ [ RegisterGradient ( "Sub" ) ]
172183 public static Tensor [ ] _SubGrad ( Operation op , Tensor [ ] grads )
173184 {
174185 var grad = grads [ 0 ] ;
@@ -198,6 +209,7 @@ public static bool _ShapesFullySpecifiedAndEqual(Tensor x, Tensor y, Tensor grad
198209 ! x_shape . Contains ( - 1 ) ;
199210 }
200211
212+ [ RegisterGradient ( "Sum" ) ]
201213 public static Tensor [ ] _SumGrad ( Operation op , Tensor [ ] grads )
202214 {
203215 var grad = grads [ 0 ] ;
@@ -231,6 +243,7 @@ public static Tensor[] _SumGrad(Operation op, Tensor[] grads)
231243 return new Tensor [ ] { gen_array_ops . tile ( grad , tile_scaling ) , null } ;
232244 }
233245
246+ [ RegisterGradient ( "RealDiv" ) ]
234247 public static Tensor [ ] _RealDivGrad ( Operation op , Tensor [ ] grads )
235248 {
236249 var grad = grads [ 0 ] ;
@@ -254,6 +267,7 @@ public static Tensor[] _RealDivGrad(Operation op, Tensor[] grads)
254267 return new Tensor [ ] { reshape2 , reshape1 } ;
255268 }
256269
270+ [ RegisterGradient ( "Sigmoid" ) ]
257271 public static Tensor [ ] _SigmoidGrad ( Operation op , Tensor [ ] grads )
258272 {
259273 var grad = grads [ 0 ] ;
@@ -266,6 +280,7 @@ public static Tensor[] _SigmoidGrad(Operation op, Tensor[] grads)
266280 } ) ;
267281 }
268282
283+ [ RegisterGradient ( "Square" ) ]
269284 public static Tensor [ ] _SquareGrad ( Operation op , Tensor [ ] grads )
270285 {
271286 var grad = grads [ 0 ] ;
@@ -279,6 +294,7 @@ public static Tensor[] _SquareGrad(Operation op, Tensor[] grads)
279294 } ) ;
280295 }
281296
297+ [ RegisterGradient ( "Pow" ) ]
282298 public static Tensor [ ] _PowGrad ( Operation op , Tensor [ ] grads )
283299 {
284300 var grad = grads [ 0 ] ;
0 commit comments