parameters: (type_value)
docstring: Converts the given `type_value` to a `DType`.
  
    Args:
      type_value: A value that can be converted to a `tf.DType`
        object. This may currently be a `tf.DType` object, a
        [`DataType` enum](https://www.tensorflow.org/code/tensorflow/core/framework/types.proto),
        a string type name, or a `numpy.dtype`.
  
    Returns:
      A `DType` corresponding to `type_value`.
  
    Raises:
      TypeError: If `type_value` cannot be converted to a `DType`.
docstring_summary: Converts the given `type_value` to a `DType`.
docstring_tokens: Converts the given type_value to a DType .
function: def as_dtype(type_value):
    """Converts the given `type_value` to a `DType`.
  
    Args:
      type_value: A value that can be converted to a `tf.DType`
        object. This may currently be a `tf.DType` object, a
        [`DataType` enum](https://www.tensorflow.org/code/tensorflow/core/framework/types.proto),
        a string type name, or a `numpy.dtype`.
  
    Returns:
      A `DType` corresponding to `type_value`.
  
    Raises:
      TypeError: If `type_value` cannot be converted to a `DType`.
    """
    if isinstance(type_value, DType):
      return type_value
  
    try:
      return _INTERN_TABLE[type_value]
    except KeyError:
      pass
  
    try:
      return _STRING_TO_TF[type_value]
    except KeyError:
      pass
  
    if isinstance(type_value, np.dtype):
      # The numpy dtype for strings is variable length. We can not compare
      # dtype with a single constant (np.string does not exist) to decide
      # dtype is a "string" type. We need to compare the dtype.type to be
      # sure it's a string type.
      if type_value.type == np.string_ or type_value.type == np.unicode_:
        return string
  
    for key, val in _NP_TO_TF:
      if key == type_value:
        return val
  
    raise TypeError(
        "Cannot convert value %r to a TensorFlow DType." % type_value)
function_tokens: def as_dtype ( type_value ) : if isinstance ( type_value , DType ) : return type_value try : return _INTERN_TABLE [ type_value ] except KeyError : pass try : return _STRING_TO_TF [ type_value ] except KeyError : pass if isinstance ( type_value , np . dtype ) : # The numpy dtype for strings is variable length. We can not compare # dtype with a single constant (np.string does not exist) to decide # dtype is a "string" type. We need to compare the dtype.type to be # sure it's a string type. if type_value . type == np . string_ or type_value . type == np . unicode_ : return string for key , val in _NP_TO_TF : if key == type_value : return val raise TypeError ( "Cannot convert value %r to a TensorFlow DType." % type_value )