mlx.core.linalg.eigvals

Contents

mlx.core.linalg.eigvals#

eigvals(a: array, *, stream: Optional[Union[Stream, Device]] = None) array#

Compute the eigenvalues of a square matrix.

This function differs from numpy.linalg.eigvals() in that the return type is always complex even if the eigenvalues are all real.

This function supports arrays with at least 2 dimensions. When the input has more than two dimensions, the eigenvalues are computed for each matrix in the last two dimensions.

Parameters:
  • a (array) – The input array.

  • stream (Stream, optional) – Stream or device. Defaults to None in which case the default stream of the default device is used.

Returns:

The eigenvalues (not necessarily in order).

Return type:

array

Example

>>> A = mx.array([[1., -2.], [-2., 1.]])
>>> eigenvalues = mx.linalg.eigvals(A, stream=mx.cpu)
>>> eigenvalues
array([3+0j, -1+0j], dtype=complex64)