Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Eigh eigenvectors are inverted

オープン
#368 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rust
領域
data

調査の方向性

Start by running the MWE from main.rs with the dependencies in Cargo.toml and compare the results for UPLO::Lower and UPLO::Upper. Trace the eigh entry point and its LAPACK argument handling; done means A @ eigenvectors matches eigenvectors @ eigenvalues without reversing rows and the reported UPLO behavior is consistent.

索引モデルが issue の本文から書いたものです。

説明

Related: #307

MWE:

Cargo.toml:

[package]
name = "EighBug"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# ndarray
ndarray = "0.15.6"
# ndarray_linalg
ndarray-linalg = { version = "0.16.0", features = ["openblas-static"] }
# num
num = "0.4.1"
# rustfmt
rustfmt = "0.10.0"

main.rs:

use ndarray::*;
use ndarray_linalg::*;
use num::complex::Complex64;

fn main() {
    let A = arr2(&[
        [
            Complex64::new(3., 0.),
            Complex64::new(2., 2.),
            Complex64::new(2., 2.),
        ],
        [
            Complex64::new(2., -2.),
            Complex64::new(3., 0.),
            Complex64::new(2., 2.),
        ],
        [
            Complex64::new(2., -2.),
            Complex64::new(2., -2.),
            Complex64::new(3., 0.),
        ],
    ]);

    println!("A = \n{}", A);

    let (eigenvalues, eigenvectors) = A.eigh(UPLO::Lower).unwrap();

    println!(
        "eigenvalues = \n{}",
        eigenvalues.mapv(|x| format!("{:.3}", x))
    );

    println!(
        "eigenvectors = \n{}",
        eigenvectors.mapv(|x| format!("{:.3}", x))
    );

    println!(
        "A @ eigenvectors = \n{}",
        A.dot(&eigenvectors).mapv(|x| format!("{:.3}", x))
    );

    println!(
        "eigenvectors @ eigenvalues = \n{}",
        eigenvectors
            .dot(&Array2::from_diag(
                &eigenvalues.mapv(|x| Complex64::from(x))
            ))
            .mapv(|x| format!("{:.3}", x))
    );

    println!("==============================");
    println!("WITH REVERSED ROWS");

    let eigenvectors = eigenvectors.slice(s![..;-1, ..]).to_owned();
    println!(
        "eigenvectors = \n{}",
        eigenvectors.mapv(|x| format!("{:.3}", x))
    );

    println!(
        "A @ eigenvectors = \n{}",
        A.dot(&eigenvectors).mapv(|x| format!("{:.3}", x))
    );

    println!(
        "eigenvectors @ eigenvalues = \n{}",
        eigenvectors
            .dot(&Array2::from_diag(
                &eigenvalues.mapv(|x| Complex64::from(x))
            ))
            .mapv(|x| format!("{:.3}", x))
    );
}

Output

A = 
[[3+0i, 2+2i, 2+2i],
 [2-2i, 3+0i, 2+2i],
 [2-2i, 2-2i, 3+0i]]
eigenvalues = 
[-1.000, 1.536, 8.464]
eigenvectors = 
[[-0.577+0.000i, -0.577+0.000i, -0.577+0.000i],
 [-0.000+0.577i, 0.500-0.289i, -0.500-0.289i],
 [0.577-0.000i, -0.289+0.500i, -0.289-0.500i]]
A @ eigenvectors = 
[[-1.732+2.309i, -1.732+0.845i, -1.732-3.155i],
 [0.000+4.041i, -1.232+0.711i, -2.232-1.289i],
 [1.732+2.309i, -1.598+1.077i, -3.598+0.077i]]
eigenvectors @ eigenvalues = 
[[0.577+0.000i, -0.887+0.000i, -4.887+0.000i],
 [0.000-0.577i, 0.768-0.443i, -4.232-2.443i],
 [-0.577+0.000i, -0.443+0.768i, -2.443-4.232i]]
==============================
WITH REVERSED ROWS
eigenvectors = 
[[0.577-0.000i, -0.289+0.500i, -0.289-0.500i],
 [-0.000+0.577i, 0.500-0.289i, -0.500-0.289i],
 [-0.577+0.000i, -0.577+0.000i, -0.577+0.000i]]
A @ eigenvectors = 
[[-0.577+0.000i, -0.443+0.768i, -2.443-4.232i],
 [0.000-0.577i, 0.768-0.443i, -4.232-2.443i],
 [0.577+0.000i, -0.887-0.000i, -4.887+0.000i]]
eigenvectors @ eigenvalues = 
[[-0.577+0.000i, -0.443+0.768i, -2.443-4.232i],
 [0.000-0.577i, 0.768-0.443i, -4.232-2.443i],
 [0.577+0.000i, -0.887+0.000i, -4.887+0.000i]]

Expected output

A @ eigenvectors should equal eigenvectors @ eigenvalues without needing to invert the row ordering.


This could very likely be a misunderstanding on my end. But it may be related to the reversal of UPLO::Upper and UPLO::Lower. For example, for the array:

A = [[3+0i, 2+2i, 2+2i],
     [   0, 3+0i, 2+2i],
     [   0,    0, 3+0i]]

eigh(UPLO::upper) returns [3, 3, 3] for the eigenvalues, which is the expected result for eigh(UPLO::lower).

主要言語
Rust
スター
452
フォーク
95
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rust-ndarray/ndarray-linalg のほかの issue

rust-ndarray/ndarray-linalg の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。