jax-ml/jax · error · ValueError
Unrecognized method {method}. The two valid methods are eith
Error message
Unrecognized method {method}. The two valid methods are either \"schur\" or \"eigen\". What it means
jax.scipy.linalg.solve_sylvester supports only method='schur' or method='eigen'; anything else reaches the else-branch raising this ValueError. The method selects the Bartels-Stewart Schur decomposition or eigendecomposition path.
Source
Thrown at jax/_src/scipy/linalg.py:3291
@jit(static_argnames=["method"])
def _solve_sylvester_2d(A: Array, B: Array, C: Array, *, method: str, tol: float) -> Array:
m, n = C.shape[-2:]
if method == "schur":
R, U = schur(A, output='complex')
S, V = schur(B.conj().T, output='complex')
F = U.conj().T @ C.astype(R.dtype) @ V
Y = _solve_sylvester_triangular_scan(R, S.conj().T, F)
X = U @ Y @ V.conj().T
elif method == "eigen":
RA, UA = jnp.linalg.eig(A)
RB, UB = jnp.linalg.eig(B)
F = solve(UA, C.astype(RA.dtype) @ UB)
W = RA[:, None] + RB[None, :]
Y = F / W
X = UA[:m,:m] @ Y[:m,:n] @ inv(UB)[:n,:n]
else:
raise ValueError(f"Unrecognized method {method}. The two valid methods are either \"schur\" or \"eigen\".")
if not dtypes.issubdtype(C.dtype, np.complexfloating):
X = X.real
return lax.cond(
jnp.any(jnp.abs(jnp.linalg.eigvals(A)[:, None] + jnp.linalg.eigvals(B)[None, :]) < tol),
lambda: jnp.zeros_like(X) * np.nan,
lambda: X,
)
@jit(static_argnames=["method"])
def solve_sylvester(A: ArrayLike, B: ArrayLike, C: ArrayLike, *, method: str = "schur", tol: float = 1e-8) -> Array:
"""
Solves the Sylvester equation
.. math::
AX + XB = C
Using one of two methods.View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use 'schur' (default, more stable) or 'eigen'
- Validate method strings before calling
Example fix
# before X = linalg.solve_sylvester(A, B, C, method='schur ') # stray space # after X = linalg.solve_sylvester(A, B, C, method='schur')
Defensive patterns
Strategy: validation
Validate before calling
if method not in ('schur','eigen'): raise ValueError(method) Type guard
def is_valid_method(m: str) -> bool: return m in ('schur', 'eigen') Prevention
- Strip/normalize method strings from configs
When it happens
Trigger: Calling solve_sylvester(A, B, C, method='qr'), method='', or a misspelled string like 'Schur'.
Common situations: Copy-paste from custom solvers; passing a method intended for a different scipy function.
Related errors
- ind must be a positive integer; got {ind=}
- Expected kind to be on of: {valid_kind}; got {kind}
- Expected kind to be one of: {valid_kind}; got {kind}
- n must be a positive power of 2; got {n}.
- scale must be None, 'sqrtn', or 'n'; got {scale!r}.
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/29692bb3f5c483f2.
Report an issue: GitHub.