Skip to content

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

@stonemaguire

Description

@stonemaguire

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) {

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