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::forNonZeroElementsInRowOrder inconsistencies #1121

Open
bernlu opened this issue Aug 23, 2023 · 0 comments
Open

CSRMatrix::forNonZeroElementsInRowOrder inconsistencies #1121

bernlu opened this issue Aug 23, 2023 · 0 comments
Labels

Comments

@bernlu
Copy link
Contributor

bernlu commented Aug 23, 2023

Creating a 2x2 laplacian CSRMatrix from a graph with self-loops is for some reason not equal to a matrix created with the same values by hand (note that the laplacian matrix is actually not corrent, see #1120 , and this issue may be related to that). Additionally, the resulting laplacian matrix is not symmetric when checked with MatrixTools::isSymmetric.

Example code:

    Graph G(2);
    G.addEdge(0, 1);

    std::cout << CSRMatrix::laplacianMatrix(G) << std::endl;
    // 1, -1,
    // -1, 1,

    G.addEdge(1, 1);
    auto lp = CSRMatrix::laplacianMatrix(G);

    std::cout << lp << std::endl;
    // 1, -1,
    // -1, -1,

    std::cout << MatrixTools::isSymmetric(lp) << std::endl;
    // 0   -- expect 1

    CSRMatrix mat(2);
    mat.setValue(0, 0, 1);
    mat.setValue(1, 0, -1);
    mat.setValue(0, 1, -1);
    mat.setValue(1, 1, -1);

    std::cout << mat << std::endl;
    // 1, -1,
    // -1, -1,

    std::cout << MatrixTools::isSymmetric(mat) << std::endl;
    // 1

    std::cout << (lp == mat) << std::endl;
    // 0   -- expect 1

Both isSymmetric and operator== use CSRMatrix::forNonZeroElementsInOrder which seems to sometimes produce wrong values for diagonal entries. For the laplacian, the lambda is called with (1,1,1) even though the value should be -1 instead of 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