parameters: (value, dtype=None, name=None, as_ref=False)
docstring: Converts the given `value` to a `Tensor`.
  
    This function converts Python objects of various types to `Tensor`
    objects. It accepts `Tensor` objects, numpy arrays, Python lists,
    and Python scalars. For example:
  
    ```python
    import numpy as np
  
    def my_func(arg):
      arg = tf.convert_to_tensor(arg, dtype=tf.float32)
      return tf.matmul(arg, arg) + arg
  
    # The following calls are equivalent.
    value_1 = my_func(tf.constant([[1.0, 2.0], [3.0, 4.0]]))
    value_2 = my_func([[1.0, 2.0], [3.0, 4.0]])
    value_3 = my_func(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32))
    ```
  
    This function can be useful when composing a new operation in Python
    (such as `my_func` in the example above). All standard Python op
    constructors apply this function to each of their Tensor-valued
    inputs, which allows those ops to accept numpy arrays, Python lists,
    and scalars in addition to `Tensor` objects.
  
    Args:
      value: An object whose type has a registered `Tensor` conversion function.
      dtype: Optional element type for the returned tensor. If missing, the
        type is inferred from the type of `value`.
      name: Optional name to use if a new `Tensor` is created.
      as_ref: True if we want the result as a ref tensor. Only used if a new
        `Tensor` is created.
  
    Returns:
      A `Tensor` based on `value`.
  
    Raises:
      TypeError: If no conversion function is registered for `value`.
      RuntimeError: If a registered conversion function returns an invalid value.
docstring_summary: Converts the given `value` to a `Tensor`.
docstring_tokens: Converts the given value to a Tensor .
function: def convert_to_tensor(value, dtype=None, name=None, as_ref=False):
    """Converts the given `value` to a `Tensor`.
  
    This function converts Python objects of various types to `Tensor`
    objects. It accepts `Tensor` objects, numpy arrays, Python lists,
    and Python scalars. For example:
  
    ```python
    import numpy as np
  
    def my_func(arg):
      arg = tf.convert_to_tensor(arg, dtype=tf.float32)
      return tf.matmul(arg, arg) + arg
  
    # The following calls are equivalent.
    value_1 = my_func(tf.constant([[1.0, 2.0], [3.0, 4.0]]))
    value_2 = my_func([[1.0, 2.0], [3.0, 4.0]])
    value_3 = my_func(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32))
    ```
  
    This function can be useful when composing a new operation in Python
    (such as `my_func` in the example above). All standard Python op
    constructors apply this function to each of their Tensor-valued
    inputs, which allows those ops to accept numpy arrays, Python lists,
    and scalars in addition to `Tensor` objects.
  
    Args:
      value: An object whose type has a registered `Tensor` conversion function.
      dtype: Optional element type for the returned tensor. If missing, the
        type is inferred from the type of `value`.
      name: Optional name to use if a new `Tensor` is created.
      as_ref: True if we want the result as a ref tensor. Only used if a new
        `Tensor` is created.
  
    Returns:
      A `Tensor` based on `value`.
  
    Raises:
      TypeError: If no conversion function is registered for `value`.
      RuntimeError: If a registered conversion function returns an invalid value.
  
    """
    error_prefix = "" if name is None else "%s: " % name
    if dtype is not None:
      dtype = dtypes.as_dtype(dtype)
    for _, funcs_at_priority in sorted(_tensor_conversion_func_registry.items()):
      for base_type, conversion_func in funcs_at_priority:
        if isinstance(value, base_type):
          ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
          if ret is NotImplemented:
            continue
          if not isinstance(ret, Tensor):
            raise RuntimeError(
                "%sConversion function %r for type %s returned non-Tensor: %r"
                % (error_prefix, conversion_func, base_type, ret))
          if dtype and not dtype.is_compatible_with(ret.dtype):
            raise RuntimeError(
                "%sConversion function %r for type %s returned incompatible "
                "dtype: requested = %s, actual = %s"
                % (error_prefix, conversion_func, base_type,
                   dtype.name, ret.dtype.name))
          return ret
    raise TypeError("%sCannot convert %r with type %s to Tensor: "
                    "no conversion function registered."
                    % (error_prefix, value, type(value)))
function_tokens: def convert_to_tensor ( value , dtype = None , name = None , as_ref = False ) : error_prefix = "" if name is None else "%s: " % name if dtype is not None : dtype = dtypes . as_dtype ( dtype ) for _ , funcs_at_priority in sorted ( _tensor_conversion_func_registry . items ( ) ) : for base_type , conversion_func in funcs_at_priority : if isinstance ( value , base_type ) : ret = conversion_func ( value , dtype = dtype , name = name , as_ref = as_ref ) if ret is NotImplemented : continue if not isinstance ( ret , Tensor ) : raise RuntimeError ( "%sConversion function %r for type %s returned non-Tensor: %r" % ( error_prefix , conversion_func , base_type , ret ) ) if dtype and not dtype . is_compatible_with ( ret . dtype ) : raise RuntimeError ( "%sConversion function %r for type %s returned incompatible " "dtype: requested = %s, actual = %s" % ( error_prefix , conversion_func , base_type , dtype . name , ret . dtype . name ) ) return ret raise TypeError ( "%sCannot convert %r with type %s to Tensor: " "no conversion function registered." % ( error_prefix , value , type ( value ) ) )