{"record":{"id":"17be50f59bfb8308","repo":"jax-ml/jax","slug":"z-must-be-a-1d-array","errorCode":null,"errorMessage":"z must be a 1D array.","messagePattern":"z must be a 1D array\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":2213,"sourceCode":"\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)\n\n\ndef lpmn_values(m: int, n: int, z: Array, is_normalized: bool) -> Array:\n  r\"\"\"The associated Legendre functions (ALFs) of the first kind.\n","sourceCodeStart":2195,"sourceCodeEnd":2231,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L2195-L2231","documentation":"jax.scipy.special.lpmn requires the output order m to equal the degree n (it computes the full m x n matrix only for the square case). Passing m != n raises NotImplementedError. m and n must also be concrete Python ints.","triggerScenarios":"Calling lpmn(m=2, n=5, z) — any m != n combination raises; traced m/n (e.g., inside jit without static args) instead fails the concrete_or_error check just before.","commonSituations":"Porting scipy.special.lpmn(m, n, x) calls that request a subset of orders (common in spherical harmonics where only some m are needed); passing m/n from batched computation as arrays rather than static ints.","solutions":["Request the full square case: lpmn(n, n, z) and slice the result rows/columns to the m you need","If m > n, slice the first m rows of the (n+1, n+1) output; keep both arguments equal","Ensure m and n are Python ints, and pass them as static to jit (static_argnums or functools.partial)"],"exampleFix":"// before\np, dp = jax.scipy.special.lpmn(2, 5, z)  # m != n\n// after\np, dp = jax.scipy.special.lpmn(5, 5, z)\np_m2, dp_m2 = p[2], dp[2]  # slice the order you need","handlingStrategy":"validation","validationCode":"assert isinstance(m, int) and isinstance(n, int) and m == n, 'lpmn requires m == n; request (n, n) and slice'","typeGuard":"def lpmn_args_ok(m, n):\n    return isinstance(m, int) and isinstance(n, int) and m == n","tryCatchPattern":null,"preventionTips":["Call lpmn(n, n, z) and slice outputs instead of requesting m != n","Pass m, n as static arguments to jit"],"tags":["jax","scipy-special","legendre","not-implemented","argument-validation"],"backgroundTag":"unsupported-api-signature","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}