parameters: (self, op, index)
return_statement: return result
docstring: Create zeros_like for the specified output of an op.
  
      If op is in a while loop that is part of gradients(), this method
      must be called in its grad loop context.
  
      Args:
        op: A tensorflow operation.
        index: the index for a specific output of the op.
  
      Returns:
        A zero tensor of the same shape of op.outputs[index].
docstring_summary: Create zeros_like for the specified output of an op.
docstring_tokens: Create zeros_like for the specified output of an op .
function: def ZerosLike(self, op, index):
      """Create zeros_like for the specified output of an op.
  
      If op is in a while loop that is part of gradients(), this method
      must be called in its grad loop context.
  
      Args:
        op: A tensorflow operation.
        index: the index for a specific output of the op.
  
      Returns:
        A zero tensor of the same shape of op.outputs[index].
      """
      if IsLoopSwitch(op): return None
      dead_branch = IsSwitch(op)
      forward_ctxt = _GetWhileContext(op)
      if forward_ctxt is None:
        # op is not in a while loop that is part of gradients().
        return ZerosLikeOutsideLoop(op, index)
      op_ctxt = op._get_control_flow_context()
      grad_state = self._map.get(forward_ctxt)
      val = ops.convert_to_tensor(op.outputs[index], name="tensor")
      shape = val.get_shape()
      if shape.is_fully_defined():
        # If the shape is known statically, just create a zero tensor with
        # the right shape in the grad loop context.
        result = constant_op.constant(0, shape=shape.dims, dtype=val.dtype)
        if dead_branch:
          # op is a cond switch. Guard the zero tensor with a switch.
          pred = grad_state.history_map.get(op_ctxt.pred.name)
          branch = op_ctxt.branch
          result = _SwitchRefOrTensor(result, pred)[1 - branch]
      else:
        # Unknown shape so keep a history of the shape at runtime.
        if dead_branch:
          # Need to add a special switch to guard the value.
          pred = op_ctxt.pred
          branch = op_ctxt.branch
          op_ctxt.outer_context.Enter()
          val = _SwitchRefOrTensor(op.inputs[0], pred)[1 - branch]
          zeros_shape = array_ops.shape_internal(val, optimize=False)
          op_ctxt.outer_context.Exit()
          val.op._set_control_flow_context(op_ctxt)
          zeros_shape.op._set_control_flow_context(op_ctxt)
        else:
          op_ctxt.Enter()
          zeros_shape = array_ops.shape_internal(val, optimize=False)
          op_ctxt.Exit()
  
        # Add forward accumulator for shape.
        grad_state.grad_context.Exit()
        history_zeros_shape = grad_state.AddForwardAccumulator(
            zeros_shape, dead_branch=dead_branch)
        grad_state.grad_context.Enter()
  
        # Create a zero tensor with the right shape.
        shape = grad_state.AddBackPropAccumulatedValue(
            history_zeros_shape, zeros_shape, dead_branch)
        result = array_ops.zeros(shape, val.dtype)
      return result
function_tokens: def ZerosLike ( self , op , index ) : if IsLoopSwitch ( op ) : return None dead_branch = IsSwitch ( op ) forward_ctxt = _GetWhileContext ( op ) if forward_ctxt is None : # op is not in a while loop that is part of gradients(). return ZerosLikeOutsideLoop ( op , index ) op_ctxt = op . _get_control_flow_context ( ) grad_state = self . _map . get ( forward_ctxt ) val = ops . convert_to_tensor ( op . outputs [ index ] , name = "tensor" ) shape = val . get_shape ( ) if shape . is_fully_defined ( ) : # If the shape is known statically, just create a zero tensor with # the right shape in the grad loop context. result = constant_op . constant ( 0 , shape = shape . dims , dtype = val . dtype ) if dead_branch : # op is a cond switch. Guard the zero tensor with a switch. pred = grad_state . history_map . get ( op_ctxt . pred . name ) branch = op_ctxt . branch result = _SwitchRefOrTensor ( result , pred ) [ 1 - branch ] else : # Unknown shape so keep a history of the shape at runtime. if dead_branch : # Need to add a special switch to guard the value. pred = op_ctxt . pred branch = op_ctxt . branch op_ctxt . outer_context . Enter ( ) val = _SwitchRefOrTensor ( op . inputs [ 0 ] , pred ) [ 1 - branch ] zeros_shape = array_ops . shape_internal ( val , optimize = False ) op_ctxt . outer_context . Exit ( ) val . op . _set_control_flow_context ( op_ctxt ) zeros_shape . op . _set_control_flow_context ( op_ctxt ) else : op_ctxt . Enter ( ) zeros_shape = array_ops . shape_internal ( val , optimize = False ) op_ctxt . Exit ( ) # Add forward accumulator for shape. grad_state . grad_context . Exit ( ) history_zeros_shape = grad_state . AddForwardAccumulator ( zeros_shape , dead_branch = dead_branch ) grad_state . grad_context . Enter ( ) # Create a zero tensor with the right shape. shape = grad_state . AddBackPropAccumulatedValue ( history_zeros_shape , zeros_shape , dead_branch ) result = array_ops . zeros ( shape , val . dtype ) return result