Repository navigation
ENH: Add format parameter to adjacency_matrix - #8545
Conversation
Add a 'format' parameter to adjacency_matrix() to allow specifying the sparse format of the returned matrix, consistent with to_scipy_sparse_array(). This includes support for 'dense' format which returns a numpy ndarray. The adjacency_matrix function is a thin wrapper around to_scipy_sparse_array but previously didn't expose the format parameter. This change simply passes it through. Closes #7980 (partial: adjacency_matrix only) Signed-off-by: edvatar <[email protected]>
rossbar
left a comment
There was a problem hiding this comment.
The kwarg should be made keyword-only and a test is needed.
|
@rossbar Thanks for the feedback! You're absolutely right about both points:
I'll implement these changes and push an update. Thanks for the clear guidance! |
rossbar
left a comment
There was a problem hiding this comment.
I took the liberty of pushing up the last few bits. This should be all set now, thanks @toroleapinc
|
Thanks @rossbar — really appreciate you pushing the final polish and the thorough review. Learned a lot from the feedback on this one! |
dschult
left a comment
There was a problem hiding this comment.
This looks good @toroleapinc Thanks very much!
And thanks @rossbar for the review --
I notice that we are still using .todense() instead of .toarray(). But that is throughout this whole module and maybe beyond -- so definitely not part of this PR. The results of todense() and toarray() are identical for sparse arrays so there shouldn't be any issues here. In it goes!
Summary
Add a
formatparameter toadjacency_matrix()to allow specifying the sparse format of the returned matrix (or'dense'for a numpy ndarray), consistent withto_scipy_sparse_array().Partial fix for #7980.
Changes
adjacency_matrix()is a thin wrapper aroundto_scipy_sparse_array()but previously didn't expose theformatparameter. This change simply passes it through.Example