Add the option to export the incidence matrix in sparse format#913
Add the option to export the incidence matrix in sparse format#913harrymvr wants to merge 1 commit intonetworkx:masterfrom harrymvr:sparse-incidence-matrix
Conversation
|
This is a good idea. In fact we could have sparse matrix versions of other functions too e.g. adjacency_matrix() and laplacian_matrix(). There are some design choices for the names and arguments for those functions and I don't think we have come to a decision on how to do it. We could do as you suggest and add a keyword argument whether you want a sparse or dense matrix format. Or we could use two different functions like we do in convert.py for generating adjacency matrices. Once you have a sparse matrix S you can easily get a dense matrix by calling D = S.todense() so that is another option (only have sparse matrix formats). So before we incorporate this code I'd like to come to a consensus on how to proceed with sparse matrices. We can comment here or maybe the mailing list too. |
|
I think we should switch to using all sparse format matrices. My reasons So +1 for sparse matrix. (Would changing them all to being sparse have Dan On Sun, Jul 28, 2013 at 10:13 AM, Aric Hagberg notifications@github.comwrote:
|
|
I'm +1 on only having sparse matrix formats and letting users use todense() to get a dense numpy matrix. It might be worth looking at how that impacts performance of some algorithms. For small graphs the sparse matrices might be slower to generate and convert. |
The incidence matrix is huge in size (#nodes x #edges) but really sparse, since there are only two non-zeros elements per column. The way the code is right now does not allow to export the incidence matrix of a large graph (million nodes by million edges) as it initializes the result as a dense matrix full of zeros. However, using a sparse representation, as the one in scipy.sparse.lil_matrix, would make it work.