jax.scipy.linalg.eigh#
- jax.scipy.linalg.eigh(a: ArrayLike, b: ArrayLike | None = None, lower: bool = True, eigvals_only: Literal[False] = False, overwrite_a: bool = False, overwrite_b: bool = False, turbo: bool = True, eigvals: None = None, type: int = 1, check_finite: bool = True) tuple[Array, Array][source]#
- jax.scipy.linalg.eigh(a: ArrayLike, b: ArrayLike | None = None, lower: bool = True, *, eigvals_only: Literal[True], overwrite_a: bool = False, overwrite_b: bool = False, turbo: bool = True, eigvals: None = None, type: int = 1, check_finite: bool = True) Array
- jax.scipy.linalg.eigh(a: ArrayLike, b: ArrayLike | None, lower: bool, eigvals_only: Literal[True], overwrite_a: bool = False, overwrite_b: bool = False, turbo: bool = True, eigvals: None = None, type: int = 1, check_finite: bool = True) Array
- jax.scipy.linalg.eigh(a: ArrayLike, b: ArrayLike | None = None, lower: bool = True, eigvals_only: bool = False, overwrite_a: bool = False, overwrite_b: bool = False, turbo: bool = True, eigvals: None = None, type: int = 1, check_finite: bool = True) Array | tuple[Array, Array]
Compute eigenvalues and eigenvectors for a Hermitian matrix
JAX implementation of
scipy.linalg.eigh().Solves the standard eigenvalue problem
a @ v = lambda * v, or the generalized problem selected bytypewhen b is specified.- Parameters:
a – Hermitian input array of shape
(..., N, N)b – Optional positive-definite Hermitian array of shape
(..., N, N). Batch dimensions of a and b must be broadcast-compatible. If None, the identity matrix is assumed.lower – if True (default), use the lower triangle after symmetrization. Otherwise use the upper triangle.
eigvals_only – If True, compute only the eigenvalues. If False (default) compute both eigenvalues and eigenvectors.
type – Specifies the generalized eigenvalue problem:
1corresponds toa @ v = lambda * b @ v,2toa @ b @ v = lambda * v, and3tob @ a @ v = lambda * v.eigvals – Not used. Only eigvals=None is supported.
overwrite_a – unused by JAX.
overwrite_b – unused by JAX.
turbo – unused by JAX.
check_finite – unused by JAX.
- Returns:
A tuple of arrays
(eigvals, eigvecs)ifeigvals_onlyis False, otherwise an arrayeigvals.eigvals: array of shape(..., N)containing the eigenvalues.eigvecs: array of shape(..., N, N)containing the eigenvectors, normalized such thatv.conj().T @ b @ vis the identity matrix fortype=1ortype=2, andv.conj().T @ inv(b) @ vfortype=3. If b is None,v.conj().T @ vis the identity matrix.
Notes
Inputs are symmetrized before computation, for correct autodiff behavior. The generalized problem is solved using a Cholesky factorization of b. If b is not positive definite, the result contains NaNs.
See also
jax.numpy.linalg.eigh(): NumPy-style eigh API.jax.lax.linalg.eigh(): XLA-style eigh API.jax.numpy.linalg.eig(): non-hermitian eigenvalue problem.jax.scipy.linalg.eigh_tridiagonal(): tri-diagonal eigenvalue problem.
Examples
Compute the standard eigenvalue decomposition of a simple 2x2 matrix:
>>> a = jnp.array([[2., 1.], ... [1., 2.]]) >>> eigvals, eigvecs = jax.scipy.linalg.eigh(a) >>> eigvals Array([1., 3.], dtype=float32) >>> eigvecs Array([[-0.70710677, 0.70710677], [ 0.70710677, 0.70710677]], dtype=float32)
Eigenvectors are orthonormal:
>>> jnp.allclose(eigvecs.T @ eigvecs, jnp.eye(2), atol=1E-5) Array(True, dtype=bool)
Solution satisfies the eigenvalue problem:
>>> jnp.allclose(a @ eigvecs, eigvecs @ jnp.diag(eigvals)) Array(True, dtype=bool)
Solve a generalized eigenvalue problem with a positive-definite matrix b:
>>> b = jnp.diag(jnp.array([2., 1.])) >>> eigvals, eigvecs = jax.scipy.linalg.eigh(a, b) >>> jnp.allclose(a @ eigvecs, (b @ eigvecs) * eigvals, atol=1E-5) Array(True, dtype=bool) >>> jnp.allclose(eigvecs.T @ b @ eigvecs, jnp.eye(2), atol=1E-5) Array(True, dtype=bool)