jax-ml/jax · error · ValueError

Expected kind to be one of: {valid_kind}; got {kind}

Error message

Expected kind to be one of: {valid_kind}; got {kind}

What it means

Same validation as 3400 but in a sibling function (inverse Pascal-type generator): `kind` must be 'symmetric', 'lower', or 'upper'. JAX throws eagerly with the list of valid values.

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)

Solutions

  1. Use exactly 'symmetric', 'lower', or 'upper'
  2. 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

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.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/77f57371f77179fb. Report an issue: GitHub.