jax-ml/jax · error · ValueError
Expected kind to be one of
Error message
Expected kind to be one of: {valid_kind}; got {kind} What it means
Validation in jax.scipy.linalg.invpascal: the inverse Pascal matrix construction has explicit formulas only for the 'symmetric', 'lower', and 'upper' Pascal kinds (defaulting to 'symmetric' when kind is None). Any other kind string fails this guard.
Solutions
- Use exactly 'symmetric', 'lower', or 'upper'
- Whitelist-validate kind before calling if it is user-supplied
Example fix
# before kind = 'LOW' linalg.inv_pascal(n, kind=kind) # after kind = 'lower' linalg.inv_pascal(n, kind=kind)
Defensive patterns
Strategy: validation
Validate before calling
if kind not in ('symmetric','lower','upper'): raise ValueError(kind) Type guard
def is_valid_kind(k: str) -> bool: return k in ('symmetric', 'lower', 'upper') Prevention
- Reuse the same validated kind constant across pascal/inv_pascal calls
When it happens
Trigger: Calling the inverse-matrix function with an invalid kind string (typo, wrong case, unsupported value like 'upper-triangular').
Common situations: Copied scipy snippets with different naming; programmatic kind selection that can emit '' or None-adjacent values.
Understand the failure class
Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.
Related errors
- Expected kind to be on of
- ind must be a positive integer; got
- n must be a positive power of 2; got
- scale must be None, 'sqrtn', or 'n'; got
- Unrecognized method . The two valid methods are either…
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/77f57371f77179fb.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/scipy/linalg.py:3080
>>> with jnp.printoptions(precision=3, suppress=True):
... print(jax.scipy.linalg.invpascal(4, kind="lower"))
... print(jax.scipy.linalg.invpascal(5))
[[ 1. -0. 0. -0.]
[-1. 1. -0. 0.]
[ 1. -2. 1. -0.]
[-1. 3. -3. 1.]]
[[ 5. -10. 10. -5. 1.]
[-10. 30. -35. 19. -4.]
[ 10. -35. 46. -27. 6.]
[ -5. 19. -27. 17. -4.]
[ 1. -4. 6. -4. 1.]]
"""
if kind is None:
kind = "symmetric"
valid_kind = ["symmetric", "lower", "upper"]
if kind not in valid_kind:
raise ValueError(f"Expected kind to be one of: {valid_kind}; got {kind}")
a = jnp.arange(n, dtype=dtypes.default_float_dtype())
i = a[:, None]
j = a[None, :]
# Lower-triangular inverse: (-1)^(i-j) * binom(i, j).
L_inv = ((-1.0) ** (i - j)) * _binom(i, j)
if kind == "lower":
return L_inv
if kind == "upper":
return L_inv.T
return jnp.dot(L_inv.T, L_inv)
@jit(static_argnames=("n", "full"))
def helmert(n: int, full: bool = False) -> Array:
r"""Construct a Helmert matrix.
View on GitHub (pinned to 1e1c6a8fc0)