jax.scipy.linalg.eigh

Contents

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 by type when 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: 1 corresponds to a @ v = lambda * b @ v, 2 to a @ b @ v = lambda * v, and 3 to b @ 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) if eigvals_only is False, otherwise an array eigvals.

  • eigvals: array of shape (..., N) containing the eigenvalues.

  • eigvecs: array of shape (..., N, N) containing the eigenvectors, normalized such that v.conj().T @ b @ v is the identity matrix for type=1 or type=2, and v.conj().T @ inv(b) @ v for type=3. If b is None, v.conj().T @ v is 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

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)