{"record":{"id":"3db7ca1d1ad23300","repo":"jax-ml/jax","slug":"dtype-dtype-r-not-understood","errorCode":null,"errorMessage":"dtype {dtype!r} not understood","messagePattern":"dtype (.+?) not understood","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/dtypes.py","lineNumber":358,"sourceCode":"\ndef to_complex_dtype(dtype: DTypeLike) -> DType:\n  ftype = to_inexact_dtype(dtype)\n  if ftype in [np.dtype('float64'), np.dtype('complex128')]:\n    return np.dtype('complex128')\n  return np.dtype('complex64')\n\n\n@functools.cache\ndef _canonicalize_dtype(x64_enabled: bool, allow_extended_dtype: bool, dtype: Any) -> DType | ExtendedDType:\n  if issubdtype(dtype, extended):\n    if not allow_extended_dtype:\n      raise ValueError(f\"Internal: canonicalize_dtype called on extended dtype {dtype} \"\n                       \"with allow_extended_dtype=False\")\n    return dtype\n  try:\n    dtype_ = np.dtype(dtype)\n  except TypeError as e:\n    raise TypeError(f'dtype {dtype!r} not understood') from e\n\n  if x64_enabled:\n    return dtype_\n  else:\n    return _dtype_to_32bit_dtype.get(dtype_, dtype_)\n\n@overload\n\n\ndef canonicalize_dtype(\n    dtype: Any, allow_extended_dtype: Literal[False] = False\n) -> DType:\n  ...\n\n\n@overload\n\n","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L340-L376","documentation":"jax.dtypes.canonicalize_dtype could not interpret the value as a numpy dtype — np.dtype(dtype) itself raised TypeError, so the object is not dtype-like (e.g. a random class instance, list, or malformed string).","triggerScenarios":"canonicalize_dtype(SomeObject()), passing an invalid dtype string like 'float128' on platforms without it, or a dataclass where __repr__/conversion breaks np.dtype.","commonSituations":"User-supplied dtype fields from YAML/config parsed into non-dtype objects; typos in dtype names in kwargs like jit(f, ...)? or custom primitives.","solutions":["Pass standard dtype specifiers: 'float32', np.float32, jnp.bfloat16","Validate with np.dtype(dtype) in a try/except before handing user config to JAX","Fix the source producing non-dtype objects (config parsing, default values)"],"exampleFix":"# before\njit(fn)(x, dtype=config['dtype'])  # dtype is a dict\n\n# after\ndtype = np.dtype(config['dtype'])  # validate early\njit(fn)(x, dtype=dtype)","handlingStrategy":"validation","validationCode":"try:\n    np.dtype(dtype)\nexcept TypeError:\n    raise ValueError(f'invalid dtype {dtype!r}') from None","typeGuard":"import numpy as np\ndef is_dtype_like(v) -> bool:\n    try:\n        np.dtype(v); return True\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    canonicalize_dtype(dtype)\nexcept TypeError:\n    dtype = np.float32  # or reject input","preventionTips":["Validate user dtype config with np.dtype at load time","Use standard dtype names/objects"],"tags":["jax","dtype","type-check","canonicalization"],"backgroundTag":"invalid-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}