parameters: (op, grad)
return_statement: return result
docstring: Gradients for an Enter are calculated using an Exit op.
  
    For loop variables, grad is the gradient so just add an exit.
    For loop invariants, we need to add an accumulator loop.
docstring_summary: Gradients for an Enter are calculated using an Exit op.
docstring_tokens: Gradients for an Enter are calculated using an Exit op .
function: def _EnterGrad(op, grad):
    """Gradients for an Enter are calculated using an Exit op.
  
    For loop variables, grad is the gradient so just add an exit.
    For loop invariants, we need to add an accumulator loop.
    """
    graph = ops.get_default_graph()
    # pylint: disable=protected-access
    grad_ctxt = graph._get_control_flow_context()
    # pylint: enable=protected-access
    if not grad_ctxt.back_prop:
      # Skip gradient computation, if the attribute `back_prop` is false.
      return grad
    if grad_ctxt.grad_state is None:
      # Pass the gradient through if we are not in a gradient while context.
      return grad
    if op.get_attr("is_constant"):
      # Add a gradient accumulator for each loop invariant.
      if isinstance(grad, ops.Tensor):
        result = grad_ctxt.AddBackpropAccumulator(op, grad)
      elif isinstance(grad, ops.IndexedSlices):
        result = grad_ctxt.AddBackpropIndexedSlicesAccumulator(op, grad)
      else:
        # TODO(yuanbyu, lukasr): Add support for SparseTensor.
        raise TypeError("Type %s not supported" % type(grad))
    else:
      result = exit(grad)
      grad_ctxt.loop_exits.append(result)
      grad_ctxt.ExitResult([result])
    return result
function_tokens: def _EnterGrad ( op , grad ) : graph = ops . get_default_graph ( ) # pylint: disable=protected-access grad_ctxt = graph . _get_control_flow_context ( ) # pylint: enable=protected-access if not grad_ctxt . back_prop : # Skip gradient computation, if the attribute `back_prop` is false. return grad if grad_ctxt . grad_state is None : # Pass the gradient through if we are not in a gradient while context. return grad if op . get_attr ( "is_constant" ) : # Add a gradient accumulator for each loop invariant. if isinstance ( grad , ops . Tensor ) : result = grad_ctxt . AddBackpropAccumulator ( op , grad ) elif isinstance ( grad , ops . IndexedSlices ) : result = grad_ctxt . AddBackpropIndexedSlicesAccumulator ( op , grad ) else : # TODO(yuanbyu, lukasr): Add support for SparseTensor. raise TypeError ( "Type %s not supported" % type ( grad ) ) else : result = exit ( grad ) grad_ctxt . loop_exits . append ( result ) grad_ctxt . ExitResult ( [ result ] ) return result