-
Notifications
You must be signed in to change notification settings - Fork 167
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
Return sparse matrix instead of dense matrix from adjacency matrix functions #1081
Comments
I think converting the graphs into a sparse matrix would be really helpful. But on the Rust side sparsemat/sprs#289 is going to be a big blocker. We could also try implementing types that are a read-only CSC/CSR matrix from Rust, but I am not sure how useful that is for users |
At least in this case since we just need to generate a sparse matrix. I think this one isn't actually super hard, albeit not as potentially optimized as possible. We should be able construct 1d arrays for each of the inputs like The thing I'm mostly hesitant about is adding a dependency on scipy to the package, as it's fairly heavy and we're not actually going to be using it for anything inside rustworkx, just for interop with sparse matrices which is a fairly small part of scipy. I wonder if we had a function like
Although if we did add a scipy dependency (including an optional one) we can probably do this call directly in rust via pyo3 fairly easily. |
@mtreinish, @IvanIsCoding Unless you do not want to re-write scipy and its sparse matrix operations in rust as well (which would be amazing but probably a bit of an overkill), adding functionality or its own sparse format does not seem to be necessary. The implemention of the COO matrix is probably just a loop over the edges and instead of filling the dense matrix, appending it to a list. The reason, I did not do that directly in python is, that in Rust it must be a lot faster which matters for the mentioned, large matrices. |
networkx gives adjacency matrices as sparse matrices and that is necessary, since for larger graphs with >100000 nodes with sparse connections, we can have a sparse e.g. coo matrix but a dense matrix does usually not fit into the memory.
I suggest, you give the option to return either a sparse (coo) matrix or its values and coordinates (as an option).
Comparison networkx
The text was updated successfully, but these errors were encountered: