{"record":{"id":"4a629ee84d0abccb","repo":"jax-ml/jax","slug":"z-dtype-is-not-supported-see-docstring-for-sup","errorCode":null,"errorMessage":"z.dtype={} is not supported, see docstring for supported types.","messagePattern":"z\\.dtype=(.+?) is not supported, see docstring for supported types\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":2208,"sourceCode":"    n: The maximum degree of the associated Legendre function, often called\n      `l` in describing ALFs. Both the degrees and orders are\n      `[0, 1, 2, ..., l_max]`, where `l_max` denotes the maximum degree.\n    z: A vector of type `float32` or `float64` containing the sampling\n      points at which the ALFs are computed.\n\n  Returns:\n    A 2-tuple of 3D arrays of shape `(l_max + 1, l_max + 1, len(z))` containing\n    the values and derivatives of the associated Legendre functions of the\n    first kind. The return type matches the type of `z`.\n\n  Raises:\n    TypeError if elements of array `z` are not in (float32, float64).\n    ValueError if array `z` is not 1D.\n    NotImplementedError if `m!=n`.\n  \"\"\"\n  dtype = lax.dtype(z)\n  if dtype not in (np.float32, np.float64):\n    raise TypeError(\n        'z.dtype={} is not supported, see docstring for supported types.'\n        .format(dtype))\n\n  if z.ndim != 1:\n    raise ValueError('z must be a 1D array.')\n\n  m = core.concrete_or_error(int, m, 'Argument m of lpmn.')\n  n = core.concrete_or_error(int, n, 'Argument n of lpmn.')\n\n  if m != n:\n    raise NotImplementedError('Computations for m!=n are not yet supported.')\n\n  l_max = n\n  is_normalized = False\n  p_vals = _gen_associated_legendre(l_max, z, is_normalized)\n  p_derivatives = _gen_derivatives(p_vals, z, is_normalized)\n\n  return (p_vals, p_derivatives)","sourceCodeStart":2190,"sourceCodeEnd":2226,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L2190-L2226","documentation":"jax.scipy.special.lpmn only accepts z arrays of dtype float32 or float64. Integer, complex, or half-precision z raises TypeError immediately, before the 1D and m/n checks.","triggerScenarios":"Calling lpmn(m, n, jnp.linspace(...)) is fine, but lpmn(m, n, jnp.array([0, 1])) (int), bfloat16 z, or complex z raises; also reached via scipy_fun wrappers in tests.","commonSituations":"Passing integer grids (e.g., indices) as evaluation points; bf16 TPU tensors; complex cosine arguments from orbital-mechanics code; forgetting that lpmn does not auto-cast unlike SciPy's more permissive handling.","solutions":["Cast z: lpmn(m, n, z.astype(jnp.float32))","Generate evaluation points with float dtypes from the start (jnp.linspace, jnp.arange(..., dtype=jnp.float32))","For complex z, note lpmn is real-only — restructure the computation or use scipy outside JAX"],"exampleFix":"// before\njax.scipy.special.lpmn(3, 3, jnp.array([0, 1, 2]))  # int32\n// after\njax.scipy.special.lpmn(3, 3, jnp.array([0, 1, 2], dtype=jnp.float32))","handlingStrategy":"validation","validationCode":"z = jnp.asarray(z, jnp.float32) if jnp.dtype(z) not in (np.float32, np.float64) else z\nlpmn(m, n, z)","typeGuard":"def float32_64(z):\n    return jnp.dtype(z) in (np.float32, np.float64)","tryCatchPattern":null,"preventionTips":["Generate z with float dtypes (linspace/arange with dtype=jnp.float32)","Don't assume SciPy-style auto-casting in JAX special functions"],"tags":["jax","scipy-special","legendre","dtype-validation"],"backgroundTag":"unsupported-input-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}