@@ -310,23 +310,26 @@ public static Tensor[] _MeanGrad(Operation op, Tensor[] grads)
310310 var input_shape = op . inputs [ 0 ] . _shape_tuple ( ) ;
311311 var output_shape = op . outputs [ 0 ] . _shape_tuple ( ) ;
312312
313+ Tensor result , factor_tensor ;
313314 if ( input_shape != null &&
314315 output_shape != null )
315316 {
316317 var input_size = np . prod ( input_shape ) ;
317318 var output_size = np . prod ( output_shape ) ;
318319 var factor = ( int ) input_size / Math . Max ( ( int ) output_size , 1 ) ;
319- var factor_tensor = constant_op . constant ( ( int ) input_size , dtype : sum_grad . dtype ) ;
320- return new Tensor [ ] { math_ops . truediv ( sum_grad , math_ops . cast ( factor_tensor , sum_grad . dtype ) ) , null } ;
320+ factor_tensor = constant_op . constant ( factor , dtype : sum_grad . dtype ) ;
321321 }
322322 else
323323 {
324324 var input_shape_tensor = array_ops . shape ( op . inputs [ 0 ] ) ;
325325 var output_shape_tensor = array_ops . shape ( op . outputs [ 0 ] ) ;
326326 var factor = _safe_shape_div ( math_ops . reduce_prod ( input_shape_tensor ) , math_ops . reduce_prod ( output_shape_tensor ) ) ;
327-
328- return new Tensor [ ] { math_ops . truediv ( sum_grad , math_ops . cast ( factor , sum_grad . dtype ) ) , null } ;
327+ throw new NotImplementedException ( "" ) ;
328+ factor_tensor = null ;
329329 }
330+
331+ result = math_ops . truediv ( sum_grad , math_ops . cast ( factor_tensor , sum_grad . dtype ) ) ;
332+ return new Tensor [ ] { result , null } ;
330333 }
331334
332335 /// <summary>
@@ -513,20 +516,23 @@ public static Tensor[] _SumGrad(Operation op, Tensor[] grads)
513516 input_shape = array_ops . shape ( op . inputs [ 0 ] ) ;
514517 return new Tensor [ ] { gen_array_ops . tile ( grad , input_shape ) , null } ;
515518 }
516- else
519+ else if ( ! input_0_shape . Contains ( - 1 ) && ! tf . context . executing_eagerly ( ) )
517520 {
518-
521+ throw new NotImplementedException ( "" ) ;
519522 }
520523 }
521524 }
522525
523526 input_shape = array_ops . shape ( op . inputs [ 0 ] ) ;
524- ops . colocate_with ( input_shape ) ;
525- var output_shape_kept_dims = math_ops . reduced_shape ( input_shape , op . inputs [ 1 ] ) ;
526- var tile_scaling = _safe_shape_div ( input_shape , output_shape_kept_dims ) ;
527- grad = gen_array_ops . reshape ( grad , output_shape_kept_dims ) ;
527+ if ( ! op . get_attr < bool > ( "keep_dims" ) )
528+ {
529+ ops . colocate_with ( input_shape ) ;
530+ var output_shape_kept_dims = math_ops . reduced_shape ( input_shape , op . inputs [ 1 ] ) ;
531+ // var tile_scaling = _safe_shape_div(input_shape, output_shape_kept_dims);
532+ grad = gen_array_ops . reshape ( grad , output_shape_kept_dims ) ;
533+ }
528534
529- return new Tensor [ ] { gen_array_ops . tile ( grad , tile_scaling ) , null } ;
535+ return new Tensor [ ] { gen_array_ops . broadcast_to ( grad , input_shape ) , null } ;
530536 }
531537
532538 [ RegisterGradient ( "RealDiv" ) ]
0 commit comments