Skip to content

Eigen::new() can panic via unwrap() on Schur decomposition failure #1594

@DiogoRibeiro7

Description

@DiogoRibeiro7

Description

Eigen::new() returns Option<Self> but internally calls .unwrap() on Schur::new(), which can panic before Eigen::new() has a chance to return None:

// src/linalg/eigen.rs, line 72
let (mut eigenvectors, mut eigenvalues) = Schur::new(m, 0).unwrap().unpack();

Schur::new returns Option<Schur<T, D>> and can fail for matrices where the Schur decomposition does not converge. When it does, the .unwrap() panics instead of propagating the failure as None.

Impact

This is inconsistent with every other decomposition in nalgebra (Cholesky::new, LU::new, SVD::try_new, etc.), which return Option/Result on failure without panicking. Users relying on Eigen::new() returning None gracefully may get unexpected panics instead.

Expected behaviour

let (mut eigenvectors, mut eigenvalues) = Schur::new(m, 0)?.unpack();
// or
let (mut eigenvectors, mut eigenvalues) = Schur::new(m, 0)
    .map(|s| s.unpack())
    .unwrap_or_else(|| return None);

Fix

Replace .unwrap() with ? (using early-return None) or an explicit match/? to propagate the failure as None from Eigen::new().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions