jax-ml/jax · error · ValueError

Invalid 'trans' value {trans}

Error message

Invalid 'trans' value {trans}

What it means

jax.scipy.linalg.solve_triangular accepts trans as 0/'N' (no transpose), 1/'T' (transpose), or 2/'C' (conjugate transpose). Any other value raises ValueError. Note these are the only accepted spellings — lowercase 't'/'n'/'c' or 'TP' etc. are rejected.

Source

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

    Array(True, dtype=bool)
  """
  del overwrite_a, overwrite_b, debug, check_finite  #unused
  valid_assume_a = ['gen', 'sym', 'her', 'pos']
  if assume_a not in valid_assume_a:
    raise ValueError(f"Expected assume_a to be one of {valid_assume_a}; got {assume_a!r}")
  return _solve(a, b, assume_a, lower)

@jit(static_argnames=('trans', 'lower', 'unit_diagonal'))
def _solve_triangular(a: ArrayLike, b: ArrayLike, trans: int | str,
                      lower: bool, unit_diagonal: bool) -> Array:
  if trans == 0 or trans == "N":
    transpose_a, conjugate_a = False, False
  elif trans == 1 or trans == "T":
    transpose_a, conjugate_a = True, False
  elif trans == 2 or trans == "C":
    transpose_a, conjugate_a = True, True
  else:
    raise ValueError(f"Invalid 'trans' value {trans}")

  a, b = promote_dtypes_inexact(jnp.asarray(a), jnp.asarray(b))

  if b.ndim == 1:
    signature = "(n,n),(n)->(n)"
  elif a.ndim == b.ndim + 1 and a.shape[-1] == b.shape[-1]:
    # Deprecation warning added 2026-03-23
    warnings.warn(
        "jax.scipy.linalg.solve_triangular: batched 1D solves with b.ndim > 1 "
        "are deprecated, and in the future will be treated as a batched 2D solve. "
        "Use solve_triangular(a, b[..., None]).squeeze(-1) to avoid this warning.",
        category=FutureWarning)
    signature = "(n,n),(n)->(n)"
  else:
    signature = "(n,n),(n,k)->(n,k)"

  return jnp_vectorize.vectorize(
      partial(lax_linalg.triangular_solve, left_side=True, lower=lower,

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Map boolean flags: use trans=1 or 'T' for transpose, 0 or 'N' for none, 2 or 'C' for conjugate transpose
  2. Normalize input: {'n':0,'t':1,'c':2}[str(trans).lower().strip()] before calling

Example fix

// before
x = jax.scipy.linalg.solve_triangular(L, b, trans=True)
// after
x = jax.scipy.linalg.solve_triangular(L, b, trans='T')
Defensive patterns

Strategy: validation

Validate before calling

_T = {0:'N','N':'N',1:'T','T':'T',2:'C','C':'C'}
trans = _T[trans]  # raises KeyError early on bad values

Type guard

null

Prevention

When it happens

Trigger: Calling solve_triangular(a, b, trans='t'), trans='N ', trans=3, or trans=True.

Common situations: Porting scipy.linalg.solve_triangular code that passed trans=0/1/2 ints but accidentally changed to a different encoding; mixing conventions with solve (which uses trans=True/False in some APIs).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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