parameters: (x, dtype, name=None)
docstring: Casts a tensor to a new type.
  
    The operation casts `x` (in case of `Tensor`) or `x.values`
    (in case of `SparseTensor`) to `dtype`.
  
    For example:
  
    ```python
    # tensor `a` is [1.8, 2.2], dtype=tf.float
    tf.cast(a, tf.int32) ==> [1, 2]  # dtype=tf.int32
    ```
  
    Args:
      x: A `Tensor` or `SparseTensor`.
      dtype: The destination type.
      name: A name for the operation (optional).
  
    Returns:
      A `Tensor` or `SparseTensor` with same shape as `x`.
  
    Raises:
      TypeError: If `x` cannot be cast to the `dtype`.
docstring_summary: Casts a tensor to a new type.
docstring_tokens: Casts a tensor to a new type .
function: def cast(x, dtype, name=None):
    """Casts a tensor to a new type.
  
    The operation casts `x` (in case of `Tensor`) or `x.values`
    (in case of `SparseTensor`) to `dtype`.
  
    For example:
  
    ```python
    # tensor `a` is [1.8, 2.2], dtype=tf.float
    tf.cast(a, tf.int32) ==> [1, 2]  # dtype=tf.int32
    ```
  
    Args:
      x: A `Tensor` or `SparseTensor`.
      dtype: The destination type.
      name: A name for the operation (optional).
  
    Returns:
      A `Tensor` or `SparseTensor` with same shape as `x`.
  
    Raises:
      TypeError: If `x` cannot be cast to the `dtype`.
    """
    base_type = dtypes.as_dtype(dtype).base_dtype
    with ops.name_scope(name, "Cast", [x]) as name:
      if isinstance(x, sparse_tensor.SparseTensor):
        values_cast = cast(x.values, base_type, name=name)
        return sparse_tensor.SparseTensor(x.indices, values_cast, x.dense_shape)
      else:
        # TODO(touts): Handle what Josh said.
        #
        # Could return ops.convert_to_tensor(x, dtype=dtype, ...)  here, but that
        # allows some conversions that cast() can't do, e.g.  casting numbers to
        # strings.
        x = ops.convert_to_tensor(x, name="x")
        if x.dtype.base_dtype == base_type:
          return x
        return gen_math_ops.cast(x, base_type, name=name)
function_tokens: def cast ( x , dtype , name = None ) : base_type = dtypes . as_dtype ( dtype ) . base_dtype with ops . name_scope ( name , "Cast" , [ x ] ) as name : if isinstance ( x , sparse_tensor . SparseTensor ) : values_cast = cast ( x . values , base_type , name = name ) return sparse_tensor . SparseTensor ( x . indices , values_cast , x . dense_shape ) else : # TODO(touts): Handle what Josh said. # # Could return ops.convert_to_tensor(x, dtype=dtype, ...)  here, but that # allows some conversions that cast() can't do, e.g.  casting numbers to # strings. x = ops . convert_to_tensor ( x , name = "x" ) if x . dtype . base_dtype == base_type : return x return gen_math_ops . cast ( x , base_type , name = name )