eig_device

Function eig_device 

Source
pub fn eig_device(
    a: impl AsRef<Array>,
    stream: impl AsRef<Stream>,
) -> Result<(Array, Array)>
Expand description

Compute the eigenvalues and eigenvectors of a square matrix.

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

Unlike [eigh], this function computes eigenvalues for general (not necessarily symmetric or Hermitian) matrices. The eigenvalues and eigenvectors may be complex.

§Params

  • a: Input array. Must be a square matrix.

§Returns

A tuple (eigenvalues, eigenvectors) where eigenvalues has shape (..., N) and eigenvectors has shape (..., N, N). The eigenvectors are stored as columns.

§Example

use mlx_rs::{Array, linalg::*, StreamOrDevice};

let a = Array::from_slice(&[1.0f32, 1.0, 3.0, 4.0], &[2, 2]);
let (eigenvalues, eigenvectors) = eig_device(&a, StreamOrDevice::cpu()).unwrap();
// eigenvalues and eigenvectors are complex even for real input