ndarray-linalg icon indicating copy to clipboard operation
ndarray-linalg copied to clipboard

wrong eigh eigenvectors for complex valued matrix

Open ungsik opened this issue 4 years ago • 0 comments

The resulting eigenvectors for eigh of complex valued matrix is wrong.

If eigh is called with the hermitian conjugate of the matrix, the resulting eigenvectors are the eigenvectors of the original matrix.

   let values = vec![
        c64::new(1.0, 0.0), c64::new(0.0, -2.0),
        c64::new(0.0, 2.0), c64::new(5.0, 0.0),
    ];
    let matrix = Array2::<c64>::from_shape_vec([2; 2], values).unwrap();
    // assertion passed
    let (eigvalues, eigvecs) = matrix.t().mapv(|v| v.conj()).eigh(UPLO::Lower).unwrap();
    for i in 0 .. 2 {
        let dot = matrix.dot(&eigvecs.column(i));
        let mul = &eigvecs.column(i).mapv(|c| c*eigvalues[i]);
        assert_close_l2!(&dot, &mul, 1.0e-10);
    }
    // assertion failed.
    let (eigvalues, eigvecs) = matrix.eigh(UPLO::Lower).unwrap();
    for i in 0 .. 2 {
        let dot = matrix.dot(&eigvecs.column(i));
        let mul = &eigvecs.column(i).mapv(|c| c*eigvalues[i]);
        assert_close_l2!(&dot, &mul, 1.0e-10);
    }

ungsik avatar Nov 17 '21 01:11 ungsik