{"record":{"id":"41690c579b020eb5","repo":"jax-ml/jax","slug":"x-dtype-dtype-is-not-supported-see-docstring-fo","errorCode":null,"errorMessage":"x.dtype={dtype} is not supported, see docstring for supported types.","messagePattern":"x\\.dtype=(.+?) is not supported, see docstring for supported types\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":3115,"sourceCode":"    function.\n\n  Raises:\n    TypeError: if elements of array `x` are not in (float32, float64).\n\n  Notes:\n    There is a different convention which defines Spence's function by the\n    integral:\n\n    .. math::\n\n       -\\int_0^x \\frac{\\log(1 - t)}{t}\\mathrm{d}t\n\n    This is our spence(1 - x).\n  \"\"\"\n  x = jnp.asarray(x)\n  dtype = lax.dtype(x)\n  if dtype not in (np.float32, np.float64):\n    raise TypeError(\n      f\"x.dtype={dtype} is not supported, see docstring for supported types.\")\n  return _spence(x)\n\n\ndef bernoulli(n: int) -> Array:\n  r\"\"\"Generate the Bernoulli numbers :math:`B_0` through :math:`B_n`, inclusive.\n\n  JAX implementation of :func:`scipy.special.bernoulli`.\n\n  Args:\n    n: integer, the index of the last Bernoulli number to generate.\n\n  Returns:\n    Array containing the Bernoulli numbers :math:`B_0` through :math:`B_n`, inclusive.\n\n  Notes:\n    ``bernoulli`` generates numbers using the :math:`B_n^-` convention,\n    such that :math:`B_1=-1/2`.","sourceCodeStart":3097,"sourceCodeEnd":3133,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L3097-L3133","documentation":"jax.scipy.special.spence (dilogarithm) accepts only float32 or float64 arrays. After jnp.asarray(x), lax.dtype(x) is checked against the whitelist and any other dtype (int, float16, bfloat16, complex) raises TypeError with the dtype interpolated.","triggerScenarios":"Calling jax.scipy.special.spence with integer inputs (e.g. spence(2)), bfloat16/float16 tensors, or complex values.","commonSituations":"Convenience calls with Python ints; half-precision pipelines on TPU/GPU; forgetting that asarray does not auto-promote ints to float here.","solutions":["Cast explicitly: spence(jnp.asarray(x, dtype=jnp.float64)) (enable x64 first if needed).","Use float32 for TPU/GPU pipelines; avoid bfloat16 around special functions.","Wrap calls in a helper that canonicalizes dtype."],"exampleFix":"# before (raises)\ny = jax.scipy.special.spence(2)\n\n# after\ny = jax.scipy.special.spence(jnp.asarray(2, dtype=jnp.float64))","handlingStrategy":"type-guard","validationCode":"x = jnp.asarray(x)\nif x.dtype not in (jnp.float32, jnp.float64):\n    x = x.astype(jnp.float64 if jax.config.x64_enabled else jnp.float32)","typeGuard":"def as_supported_float(x):\n    x = jnp.asarray(x)\n    return x if x.dtype in (jnp.float32, jnp.float64) else x.astype(jnp.float32)","tryCatchPattern":null,"preventionTips":["Never pass Python ints or half-precision tensors directly to spence.","Keep a cast-at-boundary helper for all dtype-restricted jax.scipy.special functions."],"tags":["jax","spence","dtype","typeerror","dilogarithm"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}