Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

lobpcg::TruncatedSvd maps non-converged LOBPCG results to Ok, hiding convergence failure

未關閉
#420 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
rust
領域
api

研究方向

Start in src/lobpcg/svd.rs at TruncatedSvd::decompose and inspect LobpcgResult handling around lines 162-172, then review the result type and the maxiter setup around line 105. Check src/generate.rs and issue #336 for the separate RNG concern. Done means non-convergence is no longer silently reported as success, with the chosen result API covered by appropriate tests.

由索引模型根據 Issue 內容生成。

描述

Summary

lobpcg::TruncatedSvd::decompose maps a non-converged LOBPCG result onto Ok(..), so callers cannot distinguish a converged decomposition from a failed one and may silently receive wrong singular values.

Version inspected: ndarray-linalg 0.17.0 (source from crates.io).

Where

src/lobpcg/svd.rs:162-172:

match res {
    LobpcgResult::Ok(vals, vecs, _) | LobpcgResult::Err(vals, vecs, _, _) => {
        Ok(TruncatedSvdResult {
            problem: self.problem,
            eigvals: vals,
            eigvecs: vecs,
            ngm: n > m,
        })
    }
    LobpcgResult::NoResult(err) => Err(err),
}

LobpcgResult::Err(..) carries the error as its fourth field and it is dropped on the floor. Returning the partial result is reasonable; giving the caller no way to learn that it is partial is the problem.

Contributing factor: maxiter defaults to problem.len_of(Axis(0)) * 2 (svd.rs:105), which is a small iteration budget for small inputs — exactly where I measured the worst errors in the sibling implementation.

Evidence

I want to be straightforward about what I did and did not run.

Verified by source inspection in ndarray-linalg 0.17.0: the LobpcgResult::Err(..) => Ok(..) mapping above, and the maxiter default.

Not executed against ndarray-linalg: I do not have a LAPACK backend configured locally, so I could not run a reproduction through this crate.

Measured in linfa-linalg 0.2.1, whose lobpcg::TruncatedSvd is the same algorithm with the same structure (Err((_, Some(Lobpcg{..}))) => Ok(..), same 2 * n_samples default, same epsilon * correction * λ_max cutoff). Taking X = U diag(4, 3, 2, 1) Vᵀ with U (8×4) and V (4×4) built from Sylvester–Hadamard columns, so the singular values are exactly [4, 3, 2, 1] by construction:

k=1  returned Ok  sigma=[4.0]                          max rel err=2.220e-16
k=2  returned Ok  sigma=[4.0, 3.0]                     max rel err=4.441e-16
k=3  returned Ok  sigma=[3.94368, 2.67522, 1.477172]   max rel err=2.614e-1   <== WRONG
k=4  returned Ok  sigma=[4.0, 3.0, 2.0, 1.0]           max rel err=2.517e-15

A 26% error reported as success, with neighbouring block sizes exact to machine precision. I would expect the same behaviour here given the shared structure, but I have not confirmed the exact numbers under LAPACK — if that distinction matters to you, treat the code-level finding as the claim and the numbers as indicative.

Filed in parallel as rust-ml/linfa-linalg#20.

Secondary: the result is not reproducible

decompose initialises its starting block with generate::random(..) (svd.rs:132), and generate::random uses thread_rng() (src/generate.rs:36). There is no new_with_rng equivalent, so successive runs of the same program on the same input can land on different subspaces and different component signs. Combined with the silent non-convergence above, that makes the failure intermittent as well as quiet. This overlaps with #336.

Suggested remedies

  1. Surface convergence to the caller — e.g. a converged: bool or the residual norms on TruncatedSvdResult — rather than discarding the error.
  2. Or return Err by default, with the partial result available through an explicit opt-in.
  3. Consider a seedable entry point (new_with_rng) so results are reproducible; linfa-linalg has one.

Glad to put up a PR if you have a preference on direction.

主要語言
Rust
星號
452
分支
95
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

rust-ndarray/ndarray-linalg 的其他 Issue

查看 rust-ndarray/ndarray-linalg 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。