parameters: (op, grad)
return_statement: return [math_ops.div(indicators, num_selected) * grad, None]
docstring: Gradient for Min or Max. Amazingly it's precisely the same code.
docstring_summary: Gradient for Min or Max. Amazingly it's precisely the same code.
docstring_tokens: Gradient for Min or Max . Amazingly it s precisely the same code .
function: def _MinOrMaxGrad(op, grad):
    """Gradient for Min or Max. Amazingly it's precisely the same code."""
    input_shape = array_ops.shape(op.inputs[0])
    output_shape_kept_dims = math_ops.reduced_shape(input_shape, op.inputs[1])
    y = op.outputs[0]
    y = array_ops.reshape(y, output_shape_kept_dims)
    grad = array_ops.reshape(grad, output_shape_kept_dims)
  
    # Compute the number of selected (maximum or minimum) elements in each
    # reduction dimension. If there are multiple minimum or maximum elements
    # then the gradient will be divided between them.
    indicators = math_ops.cast(math_ops.equal(y, op.inputs[0]), grad.dtype)
    num_selected = array_ops.reshape(
        math_ops.reduce_sum(indicators, op.inputs[1]), output_shape_kept_dims)
  
    return [math_ops.div(indicators, num_selected) * grad, None]
function_tokens: def _MinOrMaxGrad ( op , grad ) : input_shape = array_ops . shape ( op . inputs [ 0 ] ) output_shape_kept_dims = math_ops . reduced_shape ( input_shape , op . inputs [ 1 ] ) y = op . outputs [ 0 ] y = array_ops . reshape ( y , output_shape_kept_dims ) grad = array_ops . reshape ( grad , output_shape_kept_dims ) # Compute the number of selected (maximum or minimum) elements in each # reduction dimension. If there are multiple minimum or maximum elements # then the gradient will be divided between them. indicators = math_ops . cast ( math_ops . equal ( y , op . inputs [ 0 ] ) , grad . dtype ) num_selected = array_ops . reshape ( math_ops . reduce_sum ( indicators , op . inputs [ 1 ] ) , output_shape_kept_dims ) return [ math_ops . div ( indicators , num_selected ) * grad , None ]