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

CSRMatrix::setValue does not update isSorted causing wrong results when accessing values #1104

Open
bernlu opened this issue Jul 11, 2023 · 0 comments
Labels

Comments

@bernlu
Copy link
Contributor

bernlu commented Jul 11, 2023

The internal flag isSorted (tracks whether each row in the columnIdx vector is sorted) is not consistent with the actual state of the columnIdx vector. Inserting new values with setValue does not always keep the vector sorted, but will never update the state of isSorted. This causes incorrect results when accessing values with CSRMatrix(i,j).

Small example:

CSRMatrix A(2);
A.setValue(0, 0, 1);
A.setValue(0, 1, -1);
A.setValue(1, 0, -1);
A.setValue(1, 1, 1);
// A =
// 1 -1
// -1 1
for (index i = 0; i < A.numberOfRows(); i++) {
    for (index j = 0; j < A.numberOfColumns(); j++)
        std::cout << A(i, j) << ", ";
    std::cout << std::endl;
}

Output:

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

No branches or pull requests

1 participant