parameters: (value, ctx, dtype=None)
docstring: Converts the given `value` to an `EagerTensor`.
  
    Note that this function could return cached copies of created constants for
    performance reasons.
  
    Args:
      value: value to convert to EagerTensor.
      ctx: value of context.context().
      dtype: optional desired dtype of the converted EagerTensor.
  
    Returns:
      EagerTensor created from value.
  
    Raises:
      TypeError: if `dtype` is not compatible with the type of t.
docstring_summary: Converts the given `value` to an `EagerTensor`.
docstring_tokens: Converts the given value to an EagerTensor .
function: def convert_to_eager_tensor(value, ctx, dtype=None):
    """Converts the given `value` to an `EagerTensor`.
  
    Note that this function could return cached copies of created constants for
    performance reasons.
  
    Args:
      value: value to convert to EagerTensor.
      ctx: value of context.context().
      dtype: optional desired dtype of the converted EagerTensor.
  
    Returns:
      EagerTensor created from value.
  
    Raises:
      TypeError: if `dtype` is not compatible with the type of t.
    """
    if isinstance(value, ops.EagerTensor):
      if dtype is not None and value.dtype != dtype:
        raise TypeError("Expected tensor with type %r not %r" % (
            dtype, value.dtype))
      return value
    if dtype is not None:
      try:
        dtype = dtype.as_datatype_enum
      except AttributeError:
        dtype = dtypes.as_dtype(dtype).as_datatype_enum
    device = ctx.device_name
    handle = ctx._handle  # pylint: disable=protected-access
    if isinstance(value, (float,) + six.integer_types):
      # Use a scalar cache. This will put each scalar of each type only once on
      # each device. Scalars don't use much device memory but copying scalars can
      # trigger memcpys which are slow.
      cache_key = device, value, dtype, type(value)
      scalar_cache = ctx.scalar_cache()
      tensor = scalar_cache.get(cache_key, None)
      if tensor is not None:
        return tensor
      t = ops.EagerTensor(value, context=handle, device=device, dtype=dtype)
      scalar_cache[cache_key] = t
      return t
    else:
      return ops.EagerTensor(value, context=handle, device=device, dtype=dtype)
function_tokens: def convert_to_eager_tensor ( value , ctx , dtype = None ) : if isinstance ( value , ops . EagerTensor ) : if dtype is not None and value . dtype != dtype : raise TypeError ( "Expected tensor with type %r not %r" % ( dtype , value . dtype ) ) return value if dtype is not None : try : dtype = dtype . as_datatype_enum except AttributeError : dtype = dtypes . as_dtype ( dtype ) . as_datatype_enum device = ctx . device_name handle = ctx . _handle # pylint: disable=protected-access if isinstance ( value , ( float , ) + six . integer_types ) : # Use a scalar cache. This will put each scalar of each type only once on # each device. Scalars don't use much device memory but copying scalars can # trigger memcpys which are slow. cache_key = device , value , dtype , type ( value ) scalar_cache = ctx . scalar_cache ( ) tensor = scalar_cache . get ( cache_key , None ) if tensor is not None : return tensor t = ops . EagerTensor ( value , context = handle , device = device , dtype = dtype ) scalar_cache [ cache_key ] = t return t else : return ops . EagerTensor ( value , context = handle , device = device , dtype = dtype )