sarah-quinones / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.82k stars 61 forks source link

Error `Assertion failed` when computing eigenvalues for a particular matrix #78

Closed jlapeyre closed 12 months ago

jlapeyre commented 12 months ago

When this matrix

[
[0.0 + 0.0 * I, 0.0 + 0.0 * I, 0.0 + 0.0 * I, 2.220446049250313e-16 + -1.0000000000000002 * I],
[0.0 + 0.0 * I, 0.0 + 0.0 * I, 2.220446049250313e-16 + -1.0000000000000002 * I, 0.0 + 0.0 * I],
[0.0 + 0.0 * I, 2.220446049250313e-16 + -1.0000000000000002 * I, 0.0 + 0.0 * I, 0.0 + 0.0 * I],
[2.220446049250313e-16 + -1.0000000000000002 * I, 0.0 + 0.0 * I, 0.0 + 0.0 * I, 0.0 + 0.0 * I],
]

as a Mat<c64> is passed to eigenvalues or complex_eigenvalues, it throws an error.

numpy does compute eigenvalues:

ar = np.array([
[0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 2.220446049250313e-16 + -1.0000000000000002j],
[0.0 + 0.0j, 0.0 + 0.0j, 2.220446049250313e-16 + -1.0000000000000002j, 0.0 + 0.0j],
[0.0 + 0.0j, 2.220446049250313e-16 + -1.0000000000000002j, 0.0 + 0.0j, 0.0 + 0.0j],
[2.220446049250313e-16 + -1.0000000000000002j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],
])

In [1]: np.linalg.eigvals(ar)
Out[1]: 
array([ 1.11022302e-16-1.j, -2.22044605e-16+1.j,  1.11022302e-16-1.j,
       -2.22044605e-16+1.j])

The error messages are

Assertion failed at /home/lapeyre/.cargo/registry/src/index.crates.io-6f17d22bba15001f/faer-core-0.13.0/src/lib.rs:2093:13:
  assert!( row < this.nrows() )
with expansion:
  4 < 4

Several other matrices do give the same eigenvalues that numpy does.

Version: 0.13.1 Arch Linux

sarah-quinones commented 12 months ago

thanks for opening an issue! i've managed to reproduce the bug locally and i'm currently investigating it

sarah-quinones commented 12 months ago

should be fixed in 13.3 0.13.4
i published it just now

jlapeyre commented 12 months ago

Great. It looks like it is fixed on our end as well.