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

matrices.c: 0 not ignored when inverting diagonals in pseudoinverse #52

Open
stonemaguire opened this issue Jul 6, 2023 · 0 comments · May be fixed by #57
Open

matrices.c: 0 not ignored when inverting diagonals in pseudoinverse #52

stonemaguire opened this issue Jul 6, 2023 · 0 comments · May be fixed by #57

Comments

@stonemaguire
Copy link

zscilib/src/matrices.c

Lines 1785 to 1791 in 34c3432

/* Invert the diagonal values in 'e'. If a value is zero, do
* nothing to it. */
zsl_mtx_get(&e, g, g, &x);
if ((x < epsilon) || (x > -epsilon)) {
x = 1 / x;
zsl_mtx_set(&e, g, g, x);
}

In the if statement on line 1788, x > -epsilon always evaluates to true when x is 0 because epsilon is equal to 1e-6 and 0 is always bigger than -1e-6. This causes an incorrect output matrix with infinity values since 0 should be ignored.

I changed line 1788 to the below code to fix this issue:
if (((x < epsilon) || (x > -epsilon)) && x != 0) {

@stonemaguire stonemaguire linked a pull request Jan 17, 2024 that will close this issue
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.

1 participant