{"record":{"id":"589846cd2ab2e70d","repo":"jax-ml/jax","slug":"called-name-with-a-float0-array-float0s-do-not","errorCode":null,"errorMessage":"Called {name} with a float0 array. float0s do not support any operations by design, because they are not compatible with non-trivial vector spaces. No implicit dtype conversion is done. You can use np.zeros_like(arr, dtype=np.float) to cast a float0 array to a regular zeros array. \\nIf you didn't expect to get a float0 you might have accidentally taken a gradient with respect to an integer argument.","messagePattern":"Called (.+?) with a float0 array\\. float0s do not support any operations by design, because they are not compatible with non-trivial vector spaces\\. No implicit dtype conversion is done\\. You can use np\\.zeros_like\\(arr, dtype=np\\.float\\) to cast a float0 array to a regular zeros array\\. \\\\nIf you didn't expect to get a float0 you might have accidentally taken a gradient with respect to an integer argument\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":4250,"sourceCode":"    dtypes.python_scalar_types, array_types, [array.ArrayImpl],\n    literals.typed_scalar_types):\n  ad_util.raw_jaxval_adders[t] = _add_arrays\n\n\n### primitives\n\n\n_fixed_dtype = \\\n    lambda dtype: lambda *args, **kwargs: np.dtype(dtype)\n_complex_basetype = lambda dtype, **kwargs: np.abs(np.zeros((), dtype)).dtype\n\n_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)","sourceCodeStart":4232,"sourceCodeEnd":4268,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L4232-L4268","documentation":"float0 is JAX's dtype for tangent/gradient values of non-differentiable (integer/boolean) inputs. By design float0 supports no operations; passing such an array into a lax unop (e.g. exp, neg) raises this TypeError rather than doing any implicit conversion.","triggerScenarios":"Differentiating (grad/jacfwd/jvp) a function with respect to an integer or boolean argument and then applying a lax elementwise op to the tangent; forwarding float0 cotangents into arithmetic inside custom VJP rules.","commonSituations":"Calling jax.grad on a function whose argument is an index array, count, or mask; grad through integer state updates; custom_vjp rules forgetting to zero out integer-arg tangents.","solutions":["Differentiate only with respect to float arguments; make the arg a float (e.g. 1.0 * x) if its gradient is meaningful","In custom rules, stop gradients on integer paths with lax.stop_gradient","If you genuinely want zeros, convert: jnp.zeros_like(arr, dtype=jnp.float32) as the message suggests"],"exampleFix":"// before\ng = jax.grad(lambda i: f(i).sum())(n_ints)  # tangents are float0\n// after\ng = jax.grad(lambda x: f(x).sum())(n_ints.astype(jnp.float32))","handlingStrategy":"type-guard","validationCode":"import jax.numpy as jnp, jax.dtypes as dt\nif x.dtype == dt.float0:\n    x = jnp.zeros_like(x, dtype=jnp.float32)","typeGuard":"def is_float0(x) -> bool:\n    return x.dtype == __import__('jax').dtypes.float0","tryCatchPattern":null,"preventionTips":["Only differentiate float arguments; cast integer primals to float","stop_gradient integer/boolean paths","In custom_vjps, never forward raw tangents of non-differentiable inputs"],"tags":["jax","float0","autodiff","gradient","type-error"],"backgroundTag":"gradient-of-integer-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}