Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVD Computes Wrong Singular Values for Very Small-Valued Matrices #1368

Closed
Vollkornaffe opened this issue Mar 7, 2024 · 1 comment · Fixed by #1369
Closed

SVD Computes Wrong Singular Values for Very Small-Valued Matrices #1368

Vollkornaffe opened this issue Mar 7, 2024 · 1 comment · Fixed by #1369

Comments

@Vollkornaffe
Copy link
Contributor

This should be reproducible with nalgebra = { version = "0.32.4", features = ["rand"] }

use nalgebra::Matrix3;

fn main() {
    let id = Matrix3::<f32>::identity();
    loop {
        let r = Matrix3::<f32>::new_random();
        let m = id + r * 0.000000000000000000001;

        if m == id {
            panic!("too small")
        }

        let svd = m.svd_unordered(true, true);
        if svd.singular_values.iter().any(|s| (s - 1.).abs() > 0.1) {
            println!("Input Matrix: {m:#?}");
            println!("Singular Values: {:#?}", svd.singular_values);
            panic!();
        }
    }
}

Example output:

Input Matrix: [
    [
        1.0,
        6.23101e-24,
        2.2194742e-23,
    ],
    [
        7.9115625e-24,
        1.0,
        6.47089e-22,
    ],
    [
        1.922059e-23,
        9.848782e-22,
        1.0,
    ],
]
Singular Values: [
    [
        2.1223645,
        1.0000001,
        1.0,
    ],
]
@Ralith
Copy link
Collaborator

Ralith commented Mar 7, 2024

There was a similar issue in #1314, but I think the fix for that was included in 0.32.4. Maybe an interesting reference all the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants