jax-ml/jax · error · ValueError
Unsupported QR decomposition mode '{mode}'
Error message
Unsupported QR decomposition mode '{mode}' What it means
jax.scipy.linalg.qr only supports modes 'full', 'r', and 'economic'. SciPy's qr additionally supports 'complete' and (with pivoting) raw mode, which JAX has not implemented, so those mode strings raise ValueError.
Source
Thrown at jax/_src/scipy/linalg.py:909
@overload
def _qr(a: ArrayLike, mode: str, pivoting: Literal[True]
) -> tuple[Array, Array] | tuple[Array, Array, Array]: ...
@overload
def _qr(a: ArrayLike, mode: str, pivoting: bool
) -> tuple[Array] | tuple[Array, Array] | tuple[Array, Array, Array]: ...
@jit(static_argnames=('mode', 'pivoting'))
def _qr(a: ArrayLike, mode: str, pivoting: bool
) -> tuple[Array] | tuple[Array, Array] | tuple[Array, Array, Array]:
if mode in ("full", "r"):
full_matrices = True
elif mode == "economic":
full_matrices = False
else:
raise ValueError(f"Unsupported QR decomposition mode '{mode}'")
a, = promote_dtypes_inexact(jnp.asarray(a))
q, r, *p = lax_linalg.qr(a, pivoting=pivoting, full_matrices=full_matrices)
if mode == "r":
if pivoting:
return r, p[0]
return (r,)
if pivoting:
return q, r, p[0]
return q, r
@overload
def qr(a: ArrayLike, overwrite_a: bool = False, lwork: Any = None, *,
mode: Literal["full", "economic"], pivoting: Literal[False] = False,
check_finite: bool = True) -> tuple[Array, Array]: ...
@overload
def qr(a: ArrayLike, overwrite_a: bool = False, lwork: Any = None, *,View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use mode='full' which in JAX returns full-sized Q (equivalent to SciPy's 'complete')
- Use mode='economic' for reduced Q and R
- Fall back to jnp.linalg.qr or host-side scipy.linalg.qr for exotic modes
Example fix
// before q, r = jax.scipy.linalg.qr(a, mode='complete') // after q, r = jax.scipy.linalg.qr(a, mode='full')
Defensive patterns
Strategy: type-guard
Validate before calling
null
Type guard
_QR_MODES = {'full', 'r', 'economic'}
def jax_qr_mode_ok(mode): return mode in _QR_MODES Prevention
- Map SciPy mode names to JAX ones ('complete' -> 'full') in a port shim
- Check jax.scipy docs for supported subsets before porting
When it happens
Trigger: Calling jax.scipy.linalg.qr(a, mode='complete') or mode='raw'.
Common situations: Directly porting scipy.linalg.qr calls that use mode='complete' to get a full Q of shape (M, M) when M > N.
Related errors
- mode must be 'right' or 'left', got {mode!r}
- ind must be a positive integer; got {ind=}
- multi_dot requires at least two arrays; got len(arrays)={len
- Expected 'output' to be either 'real' or 'complex', got {out
- Array shapes are not compatible for Q @ c operation: a has s
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/98c508b026b4046c.
Report an issue: GitHub.