MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _MeanGrad

Function _MeanGrad

tensorflow/python/ops/math_grad.py:235–251  ·  view source on GitHub ↗

Gradient for Mean.

(op, grad)

Source from the content-addressed store, hash-verified

233
234@ops.RegisterGradient("Mean")
235def _MeanGrad(op, grad):
236 """Gradient for Mean."""
237 sum_grad = _SumGrad(op, grad)[0]
238 input_shape = op.inputs[0]._shape_tuple() # pylint: disable=protected-access
239 output_shape = op.outputs[0]._shape_tuple() # pylint: disable=protected-access
240 if (input_shape is not None and output_shape is not None and
241 None not in input_shape and None not in output_shape):
242 input_size = np.prod(input_shape)
243 output_size = np.prod(output_shape)
244 factor = input_size // max(output_size, 1)
245 factor = constant_op.constant(factor, dtype=sum_grad.dtype)
246 else:
247 input_shape = array_ops.shape(op.inputs[0])
248 output_shape = array_ops.shape(op.outputs[0])
249 factor = _safe_shape_div(
250 math_ops.reduce_prod(input_shape), math_ops.reduce_prod(output_shape))
251 return math_ops.truediv(sum_grad, math_ops.cast(factor, sum_grad.dtype)), None
252
253
254@ops.RegisterGradient("Prod")

Callers

nothing calls this directly

Calls 7

_SumGradFunction · 0.85
_safe_shape_divFunction · 0.85
maxFunction · 0.50
_shape_tupleMethod · 0.45
constantMethod · 0.45
shapeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected