{"record":{"id":"7b1592f0295ece71","repo":"jax-ml/jax","slug":"does-not-accept-dtype-accepted-dtypes-are-s-7b1592","errorCode":null,"errorMessage":"{} does not accept dtype {}. Accepted dtypes are subtypes of {}.","messagePattern":"(.+?) does not accept dtype (.+?)\\. Accepted dtypes are subtypes of (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":4262,"sourceCode":"_strip_weak_type = lambda *args, **_: False\n\n\ndef unop_dtype_rule(result_dtype, accepted_dtypes, name, aval,\n                    supports_narrow_ints=True, **kwargs):\n  if aval.dtype == dtypes.float0:\n    raise TypeError(\n        f\"Called {name} with a float0 array. \"\n        \"float0s do not support any operations by design, because they \"\n        \"are not compatible with non-trivial vector spaces. No implicit dtype \"\n        \"conversion is done. You can use np.zeros_like(arr, dtype=np.float) \"\n        \"to cast a float0 array to a regular zeros array. \\n\"\n        \"If you didn't expect to get a float0 you might have accidentally \"\n        \"taken a gradient with respect to an integer argument.\")\n  if not any(dtypes.issubdtype(aval.dtype, t) for t in accepted_dtypes):\n    msg = '{} does not accept dtype {}. Accepted dtypes are subtypes of {}.'\n    typename = dtype_to_string(aval.dtype)\n    accepted_typenames = (t.__name__ for t in accepted_dtypes)\n    raise TypeError(msg.format(name, typename, ', '.join(accepted_typenames)))\n  if (not supports_narrow_ints) and aval.dtype in [dtypes.uint2, dtypes.int2, dtypes.uint4, dtypes.int4]:\n    raise TypeError(f'{name} does not accept dtype {dtype_to_string(aval.dtype)}.'\n                    ' Support for narrow-width integers is platform-dependent'\n                    ' and limited to a few specific operations, e.g. basic'\n                    ' arithmetic and type casting.')\n  return result_dtype(aval.dtype, **kwargs)\n\ndef default_unop_reduced_rule(aval):\n  return getr(aval)\n\ndef unop_ur_rule(name, aval, **kwargs):\n  reduced = default_unop_reduced_rule(aval)\n  if any(getu(aval)):\n    raise NotImplementedError(\n        f'unreduced rule for {name} is not implemented. Please'\n        ' file an issue at https://github.com/jax-ml/jax/issues')\n  return frozenset(), reduced, None\n","sourceCodeStart":4244,"sourceCodeEnd":4280,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L4244-L4280","documentation":"JAX lax elementwise ops (unops built via unop_dtype_rule, e.g. exp, floor, conj) restrict their input dtypes to accepted_dtypes (typically subtypes of floating/complex/integer). If the input dtype is not a subtype of any accepted category, this TypeError is raised listing what is allowed.","triggerScenarios":"Passing an unsupported dtype to a lax unop: e.g. a string/object dtype, bool where only inexact accepted, or a truncated float16 where the op's accepted list excludes it.","commonSituations":"Feeding object/string arrays from data loading into lax math; applying float-only ops (expm1, tanh on some paths) to integers when the op requires inexact; using custom dtypes not registered with the op.","solutions":["Cast the input to an accepted dtype first: x.astype(jnp.float32)","Check the op's docstring for accepted dtypes and pick a supported variant (e.g. use float input for exp/log)","For bool inputs, convert with .astype(jnp.float32) before math ops"],"exampleFix":"// before\ny = lax.exp(int_array)\n// after\ny = lax.exp(int_array.astype(jnp.float32))","handlingStrategy":"type-guard","validationCode":"import jax.numpy as jnp\nif not jnp.issubdtype(x.dtype, jnp.floating):\n    x = x.astype(jnp.float32)\nout = lax.exp(x)","typeGuard":"def has_dtype_subtype(x, categories) -> bool:\n    import numpy as np\n    return any(np.issubdtype(x.dtype, t) for t in categories)","tryCatchPattern":null,"preventionTips":["Normalize inputs to float32/complex64 at pipeline entry","Check op docstrings for accepted dtypes before use"],"tags":["jax","lax","dtype-validation","type-error"],"backgroundTag":"unsupported-dtype-for-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}