Read Matrix Market with fast_matrix_market#391
Read Matrix Market with fast_matrix_market#391eriknw merged 22 commits intopython-graphblas:mainfrom
fast_matrix_market#391Conversation
|
Changes unknown |
|
CC , @alugowski
@alugowski, when writing Matrix Market files, do you recommend passing scipy CSR or CSC matrices instead of COO? I'm curious whether |
| if _output_type(A) is _Vector: | ||
| indices, values = A.to_coo(sort=False) | ||
| s = COO(indices, values, shape=A.shape) |
There was a problem hiding this comment.
btw @SultanOrazbayev I just special-cased Vector in to_pydata_sparse, b/c previously it was creating a (1, n)-shaped sparse array from a Vector instead of a (n,)-shaped array.
There was a problem hiding this comment.
Oops, sorry about that!
But run `autoflake`, `isort`, `pyupgrade`, and `black` first (for now).
SultanOrazbayev
left a comment
There was a problem hiding this comment.
Looks great, @eriknw !
| try: | ||
| from fast_matrix_market import mmwrite # noqa: F811 | ||
| except ImportError: # pragma: no cover (import) | ||
| if engine != "auto": | ||
| raise ImportError( | ||
| "fast_matrix_market is required to write Matrix Market files " | ||
| f'using the "{engine}" engine' |
There was a problem hiding this comment.
Not sure to what extent DRY principle is useful here, but perhaps there is scope for generalising this check for suitable import as some utility function (as a separate PR).
There was a problem hiding this comment.
I'm open to such a PR :)
You may notice that my style sometimes doesn't adhere to DRY for small, straightforward (to me) things, but I suspect there are cases where things could be improved.
|
Thanks for reviewing @SultanOrazbayev! I just finished the final TODO for this PR--I added documentation to |
Closes #384.
This uses
fast_matrix_market(which looks pretty fast) by default if available, but will fall back toscipyif necessary.scipyis still necessary to be installed even if using "fast_matrix_market" engine.There were three small issues I encountered that I plan to raise upstream, but I was able to work around them.
TODO:
fast-matrix-marketto get better performance: https://python-graphblas.readthedocs.io/en/latest/user_guide/io.htmlfrom_dense/to_dense