jax-ml/jax · error · ValueError

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

Error message

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

What it means

Raised by jax.scipy.linalg.lesp... actually the matrix-generation helper (e.g. hadamard/pascal-family) when the `kind` argument is not one of 'symmetric', 'lower', 'upper'. JAX validates the string up front because downstream code branches on it. It mirrors scipy's parameter but with eager checking.

Source

Thrown at jax/_src/scipy/linalg.py:3008

     [1. 1. 0.]
     [1. 2. 1.]]
    [[1. 1. 1. 1.]
     [0. 1. 2. 3.]
     [0. 0. 1. 3.]
     [0. 0. 0. 1.]]
    [[ 1.  1.  1.  1.  1.]
     [ 1.  2.  3.  4.  5.]
     [ 1.  3.  6. 10. 15.]
     [ 1.  4. 10. 20. 35.]
     [ 1.  5. 15. 35. 70.]]
  """
  if kind is None:
    kind = "symmetric"

  valid_kind = ["symmetric", "lower", "upper"]

  if kind not in valid_kind:
    raise ValueError(f"Expected kind to be on of: {valid_kind}; got {kind}")

  a = jnp.arange(n, dtype=np.float32)

  L_n = _binom(a[:, None], a[None, :])

  if kind == "lower":
    return L_n

  if kind == "upper":
    return L_n.T

  return jnp.dot(L_n, L_n.T)

@jit
def _binom(n, k):
  a = lax.lgamma(n + 1.0)
  b = lax.lgamma(n - k + 1.0)
  c = lax.lgamma(k + 1.0)

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Set kind to one of the exact strings 'symmetric', 'lower', or 'upper'
  2. Check for leading/trailing whitespace or wrong case in the string
  3. If kind came from config/CLI input, normalize and validate it before passing

Example fix

# before
linalg.pascal(n, kind='Lower')
# after
linalg.pascal(n, kind='lower')
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 public linalg routine with kind='Low', kind='diag', or any misspelled/unsupported string; default is 'symmetric' when kind is None.

Common situations: Porting scipy code that used a different spelling, passing kind positionally with the wrong argument order, or typos/case mismatches.

Related errors


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