parameters: (x, y, y_shape)
return_statement: return grads[0], dy_orig
docstring: Returns a node to compute gradient of x wrt y.
docstring_summary: Returns a node to compute gradient of x wrt y.
docstring_tokens: Returns a node to compute gradient of x wrt y .
function: def _compute_dx_and_dy(x, y, y_shape):
    """Returns a node to compute gradient of x wrt y."""
    # We make up a dy so that we can compute the gradients. We don't really use
    # the value of dy -- we will always feed it. We need to add an identity node
    # so that we can always feed it properly. Otherwise, for the Add operation,
    # dx is the same as dy and we cannot fetch the tensor that we are feeding.
    with x.graph.as_default():
      dy_orig = constant_op.constant(1.0, shape=y_shape, dtype=y.dtype)
      dy = array_ops.identity(dy_orig)
    # We compute the gradients for x wrt. y
    grads = gradients.gradients(y, x, dy)
    assert len(grads) == 1
    return grads[0], dy_orig
function_tokens: def _compute_dx_and_dy ( x , y , y_shape ) : # We make up a dy so that we can compute the gradients. We don't really use # the value of dy -- we will always feed it. We need to add an identity node # so that we can always feed it properly. Otherwise, for the Add operation, # dx is the same as dy and we cannot fetch the tensor that we are feeding. with x . graph . as_default ( ) : dy_orig = constant_op . constant ( 1.0 , shape = y_shape , dtype = y . dtype ) dy = array_ops . identity ( dy_orig ) # We compute the gradients for x wrt. y grads = gradients . gradients ( y , x , dy ) assert len ( grads ) == 1 return grads [ 0 ] , dy_orig