Eigh eigenvectors are inverted
还没有人认领这个 Issue。
评估
调研方向
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
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-ndarray/ndarray-linalg 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
rust-ndarray/ndarray-linalg#420 ·
-
Thin SVD未关闭
难度 5/5 一周以上 新手友好度 38/100
rust-ndarray/ndarray-linalg#414 ·
-
难度 5/5 一周以上 新手友好度 30/100
rust-ndarray/ndarray-linalg#413 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
rust-ndarray/ndarray-linalg#404 ·
-
难度 4/5 3-5 天 新手友好度 35/100
rust-ndarray/ndarray-linalg#402 · 1 条评论 ·
查看 rust-ndarray/ndarray-linalg 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[Bug]: Bedrock request metadata forwarding does not work for /embeddings可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug llm translation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
pytest plugin: a crashed xdist worker aborts the whole session with INTERNALERROR可能已有人在做 @hazelxue 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
skillfs: one malformed chat-log line aborts the entire skill-usage analysis (skill_usage_from_chat_logs.py)可能已有人在做 @zjncs 今天认领。 未关闭component:skillfs
难度 2/5 1-3 小时 新手友好度 82/100
agentic-os-org/ANOLISA#6116 · 1 条评论 ·
维护者通常 1 天内回复