Giter Site home page Giter Site logo

linalg svd unwrap issues about linfa HOT 8 OPEN

rust-ml avatar rust-ml commented on June 30, 2024
linalg svd unwrap issues

from linfa.

Comments (8)

termoshtt avatar termoshtt commented on June 30, 2024 1

I also reproduced this issue. This unwrap occurs when the input vector temp at https://github.com/ADMoreau/Rust-PCA/blob/1cce2f34e60bfa59faec219fd45a62a14e7471eb/processing/src/rPCA/algorithm.rs#L95 becomes NaN array.

With my some debug code

      let temp: Array2<f64> = X.to_owned().clone();
      println!("temp[0, 0] = {}", temp[(0, 0)]);
      println!("temp[0, 1] = {}", temp[(0, 1)]);
      println!("temp[1, 0] = {}", temp[(1, 0)]);
      let (u, s, v) = temp.svd(true, true).unwrap();

the end of log becomes following:

$ cd preprocessing
$ cargo test --features=intel-mkl
...
[/home/teramura/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-linalg-0.12.0/src/lapack/svd.rs:83] ldvt = 100
temp[0, 0] = -483774241208677100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
temp[0, 1] = -1581024226846399000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
temp[1, 0] = -417737396116675400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
[/home/teramura/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-linalg-0.12.0/src/lapack/svd.rs:83] ldvt = 100
temp[0, 0] = NaN
temp[0, 1] = NaN
temp[1, 0] = NaN
[/home/teramura/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-linalg-0.12.0/src/lapack/svd.rs:83] ldvt = 100
thread 'rPCA::algorithm::tests::test_rPCA' panicked at 'called `Result::unwrap()` on an `Err` value: Lapack { return_code: -6 }', src/libcore/result.rs:1165:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

I did not trace why it becomes NAN yet...
Anyway, this is an error message issue for ndarray-linalg, thanks for notification @LukeMathWalker

from linfa.

LukeMathWalker avatar LukeMathWalker commented on June 30, 2024

Can you post the full backtrace for the case that panics?
If the code you are working on is already here on GitHub a link would be useful to clone and reproduce.

from linfa.

ADMoreau avatar ADMoreau commented on June 30, 2024

Here is the code https://github.com/ADMoreau/Rust-PCA The issue only happens in the rPCA function, PCA works fine. Sorry if the code is hard to read I haven't put all of the docs in yet. backtrace -

[/home/austin/.cargo/registry/src/github.com-1ecc6299db9ec823/ndarray-linalg-0.12.0/src/lapack/svd.rs:83] ldvt = 100

called Result::unwrap() on an Err value: Lapack { return_code: -6 }
thread 'rPCA::algorithm::tests::test_rPCA' panicked at 'called Result::unwrap() on an Err value: Lapack { return_code: -6 }', src/libcore/result.rs:1189:5
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:84
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:61
4: core::fmt::write
at src/libcore/fmt/mod.rs:1024
5: std::io::Write::write_fmt
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/libstd/io/mod.rs:1428
6: std::io::impls::<impl std::io::Write for alloc::boxed::Box>::write_fmt
at src/libstd/io/impls.rs:156
7: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:65
8: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:50
9: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:193
10: std::panicking::default_hook
at src/libstd/panicking.rs:207
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:471
12: rust_begin_unwind
at src/libstd/panicking.rs:375
13: core::panicking::panic_fmt
at src/libcore/panicking.rs:82
14: core::result::unwrap_failed
at src/libcore/result.rs:1189
15: core::result::Result<T,E>::unwrap
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/libcore/result.rs:957
16: processing::rPCA::algorithm::Do
at processing/src/rPCA/algorithm.rs:95
17: processing::rPCA::algorithm::rPCA::fit
at processing/src/rPCA/algorithm.rs:49
18: processing::rPCA::algorithm::tests::test_rPCA
at processing/src/rPCA/algorithm.rs:165
19: processing::rPCA::algorithm::tests::test_rPCA::{{closure}}
at processing/src/rPCA/algorithm.rs:158
20: core::ops::function::FnOnce::call_once
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/libcore/ops/function.rs:232
21: <alloc::boxed::Box as core::ops::function::FnOnce>::call_once
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/liballoc/boxed.rs:969
22: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:81
23: std::panicking::try
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/libstd/panicking.rs:270
24: std::panic::catch_unwind
at /rustc/4007d4ef26eab44bdabc2b7574d032152264d3ad/src/libstd/panic.rs:394
25: test::run_test_in_process
at src/libtest/lib.rs:570
26: test::run_test::run_test_inner::{{closure}}
at src/libtest/lib.rs:473
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

from linfa.

ADMoreau avatar ADMoreau commented on June 30, 2024

If you have any other comments on the code let me know so I can include it before pushing it

from linfa.

LukeMathWalker avatar LukeMathWalker commented on June 30, 2024

Ok, I cloned the repo and I managed to reproduce the test panic.

from linfa.

LukeMathWalker avatar LukeMathWalker commented on June 30, 2024

So, the panic doesn't happen the first time Do is called (which contains the call to .svd) - several SVD calls end successfully before you see the one that panics.

The error message on the console says:

thread 'rPCA::algorithm::tests::test_rPCA' panicked at 'called `Result::unwrap()` on an `Err` value: Lapack { return_code: -6 }', src/libcore/result.rs:1188:5

Looking at ndarray-linalg, we can see that the underlying LAPACK routine being called should be dgesvd ( https://github.com/rust-ndarray/ndarray-linalg/blob/cdc6db1fb5442c6e286c57e226933b1285211d92/src/lapack/svd.rs#L83 ).

Checking LAPACK's reference, it seems we are looking at line 291 here - http://www.netlib.org/lapack/explore-html/d1/d7e/group__double_g_esing_ga84fdf22a62b12ff364621e4713ce02f2.html#ga84fdf22a62b12ff364621e4713ce02f2
Now I just need to figure out what it means 😅

from linfa.

LukeMathWalker avatar LukeMathWalker commented on June 30, 2024

Could you provide some insights here @termoshtt?

from linfa.

LukeMathWalker avatar LukeMathWalker commented on June 30, 2024

I am bit confused because looking at LAPACK's code, it seems to be erroring because the LDA doesn't satisfy that equation. But this doesn't seem to be the case, given that the LDA is consistently 100 and it doesn't change throughout the computation.

from linfa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.