Fast and full-featured Matrix Market file I/O
Project description
Fast and full-featured Matrix Market file I/O package for Python.
Fastest way to read and write any Matrix Market .mtx
file into a dense ndarray, sparse coordinate (triplet) arrays, or SciPy sparse matrix.
Implemented as a Python binding of the C++ fast_matrix_market library.
pip install fast_matrix_market
Usage
import fast_matrix_market as fmm
Read as scipy sparse matrix
>>> a = fmm.mmread("eye3.mtx")
>>> a
<3x3 sparse matrix of type '<class 'numpy.float64'>'
with 3 stored elements in COOrdinate format>
>>> print(a)
(0, 0) 1.0
(1, 1) 1.0
(2, 2) 1.0
Read as raw coordinate/triplet arrays
>>> (data, (rows, cols)), shape = fmm.read_coo("eye3.mtx")
>>> rows, cols, data
(array([0, 1, 2], dtype=int32), array([0, 1, 2], dtype=int32), array([1., 1., 1.]))
Read as dense ndarray
>>> a = fmm.read_array("eye3.mtx")
>>> a
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
Write any of the above to a file
>>> fmm.mmwrite("matrix_out.mtx", a)
Write to streams (read from streams too)
>>> bio = io.BytesIO()
>>> fmm.mmwrite(bio, a)
Read only the header
>>> header = fmm.read_header("eye3.mtx")
header(shape=(3, 3), nnz=3, comment="3-by-3 identity matrix", object="matrix", format="coordinate", field="real", symmetry="general")
>>> header.shape
(3, 3)
>>> header.to_dict()
{'shape': (3, 3), 'nnz': 3, 'comment': '3-by-3 identity matrix', 'object': 'matrix', 'format': 'coordinate', 'field': 'real', 'symmetry': 'general'}
Note: SciPy is only a runtime dependency for the mmread
and mmwrite
methods. All others depend only on NumPy.
Compared to scipy.io.mmread()
The fast_matrix_market.mmread()
and mmwrite()
methods are direct replacements for their respective SciPy versions.
Compared to SciPy v1.10.0:
-
Significant performance boost
All cores on the system are used by default, use the
parallelism
argument to override. SciPy's routines are single-threaded. -
64-bit indices, but only if the matrix dimensions require it.
scipy.io.mmread()
crashes on large matrices (dimensions > 231) because it uses 32-bit indices on most platforms. -
Directly write CSC/CSR matrices with no COO intermediary.
-
longdouble
Read and writelongdouble
/longcomplex
values for more floating-point precision on platforms that support it (e.g. 80-bit floats).Just pass
long_type=True
argument to any read method to uselongdouble
arrays. SciPy can writelongdouble
matrices but reads usedouble
precision.Note: Many platforms do not offer any precision greater than
double
even if thelongdouble
type exists. On those platformslongdouble == double
so check your Numpy for support. As of writing only Linux tends to havelongdouble > double
. -
Vector files
Read 1D vector files.scipy.io.mmread()
throws aValueError
.
Differences
- If no symmetry is specified
scipy.io.mmwrite
will search the matrix for one. This is a very slow process that significantly impacts writing time for all matrices, including non-symmetric ones. It can be disabled by settingsymmetry="general"
, but that is easily forgotten.fast_matrix_market.mmwrite()
only looks for symmetries if thefind_symmetry=True
argument is passed. precision
argument tommwrite()
is currently ignored. Floats may be written with more precision than desired.
Quick way to try
Replace scipy.io.mmread
with fast_matrix_market.mmread
to quickly see if your scripts would benefit from a refactor:
import scipy.io
import fast_matrix_market as fmm
scipy.io.mmread = fmm.mmread
scipy.io.mmwrite = fmm.mmwrite
Dependencies
- No dependencies to read/write MatrixMarket headers.
numpy
to read/write arrays (i.e.read_array()
andread_coo()
). SciPy is not required.scipy
to read/writescipy.sparse
sparse matrices (i.e.read_scipy()
andmmread()
).
Development
This Python binding is implemented using pybind11 and built with scikit-build.
All code is in the python/ directory. If you make any changes simply install the package directory to build it:
pip install python/ -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for fast_matrix_market-1.4.0-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7738bbc63f5e4f9759b217f33c6ba46a4a1495a1c13605daa1af8c35e86a572d |
|
MD5 | 3a4a317d7f99297606f21827ac624fb9 |
|
BLAKE2b-256 | 823e6748671897d6e35c19e9d34805e0fe1e8e7d32d40ef731b9c8e8811068f5 |
Hashes for fast_matrix_market-1.4.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf19fcde442b1856797eea1dc79e3011ef2d8768f08e87932d4f483bea0e96b |
|
MD5 | cca2f6b33cb123ac5c0dd046ec5bbf43 |
|
BLAKE2b-256 | 6cda4f5d16e034018bdf58389d5d77fc41348e35b1d240a727f144257514bbc4 |
Hashes for fast_matrix_market-1.4.0-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19abaadd8f5616bc92876d25777a44e6da9c3eb45944da334c40b47cda971988 |
|
MD5 | 924e5544ab0084d4626712a6649b76a3 |
|
BLAKE2b-256 | c851b4f8fc96ba96d44315b3f173ddb5f4b16a49213914b6fd0cb74d8a806d60 |
Hashes for fast_matrix_market-1.4.0-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa597485e2f5241a2985bcd3cb6781c309dab715db1a8f9aefdedb2d853d4a23 |
|
MD5 | 668b848c161e747b64106dfc32a05b9a |
|
BLAKE2b-256 | 6f74fad9067fd44129634b3894042eb3179cd414fa8c0e40160c0e709c109fd8 |
Hashes for fast_matrix_market-1.4.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a53ae5700a50480b885186634b9bf0b293aa48b1ad4cfc7a2297ab5d6f4a6ba |
|
MD5 | 83e0227adc72ac145b0790a48fe737c6 |
|
BLAKE2b-256 | 5764e13509b7e976014119d00ffe38e462a5f89793f582e1b33619804993653c |
Hashes for fast_matrix_market-1.4.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e80d642770ee85c112c6421a924fce2571170b95c58cc7db062a937b6f5c85 |
|
MD5 | f4a40d721eaf4df60b4976f4bc1d3cc4 |
|
BLAKE2b-256 | d6a7d3d8cc903a75da9834fcc668671487e39a5bf29358e90aabc4f14ed6af0f |
Hashes for fast_matrix_market-1.4.0-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 790eef62ae312165063a5a9989335fcce2ae37bf0c3596c246917195cdb253c4 |
|
MD5 | 4a8c6933fbb42c86463c149e8352000e |
|
BLAKE2b-256 | 6aa01a8547478531e6ac8fef3c8966464dfdc512ee8145f2d1c7ee2a45675b69 |
Hashes for fast_matrix_market-1.4.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e171fd80d40374c0cdc4cc8caeca4d4bfd92e6e5983bc7d8841f9ec2e0017028 |
|
MD5 | 882147673035fea5e60db36ab35266e6 |
|
BLAKE2b-256 | cd63b9626246230a83e520728c487633efb48b5bc2dcc7a6154401babe00c568 |
Hashes for fast_matrix_market-1.4.0-pp37-pypy37_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3f499cb2ebb2a7593d560698d9719e137d2b86cf68f01341b6f2acba73ebfba |
|
MD5 | 8848c37fd12a46030863e066d00c254d |
|
BLAKE2b-256 | 40c3a7855de94c45ecd243d8c36e12c253dd92144e0c461b1341b11172c0b66e |
Hashes for fast_matrix_market-1.4.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78b81d9581b89093311dff6c2289c609e962969bae977cb0cfc942d1dbef152a |
|
MD5 | 320766fe5f3d3bba662d6cb96b90d4f2 |
|
BLAKE2b-256 | fff2a35e71bf289c24596da8730b7cae653d1912cf4122d2bb6088093bc54efe |
Hashes for fast_matrix_market-1.4.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 184ff81f9f329b092a99807085381ed3cb2ea70b408e8c3bee79b7d1b47311dd |
|
MD5 | ded9ec9da55215fa794cba7be22df02b |
|
BLAKE2b-256 | d491b359e495ce21fca881b4bc4708bf0612e49814192dff9cd8623e1a055ced |
Hashes for fast_matrix_market-1.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21a51733c4e11e8a8e572915904839408108d2e21fc9db9b9f01d37263f8e3dd |
|
MD5 | 914554e30c62fd0516a938a670a1e732 |
|
BLAKE2b-256 | 415604337eee433da62cdc2e4efa3464d0db744bba26bfde82cd7509987cc07a |
Hashes for fast_matrix_market-1.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e61988125fec432d4347588f2ea73d3911362805132f84fd37bdde20cc568ce5 |
|
MD5 | cfd67dfd46685a8121554e6412c9fe7a |
|
BLAKE2b-256 | 9160553d9c2ffb24330260294c8b25e10faee6b0e996b59a8af1823b48b9333e |
Hashes for fast_matrix_market-1.4.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2c560f8363299d31064a0a7e2537a26d829c99e6e72827032eb58b73773f15d |
|
MD5 | 09849dbf018305e5936e5a06aa8f01c7 |
|
BLAKE2b-256 | 70885d78548db59d380acc97f2e27f0ce7aba693b46ac03bad121af5f43755a3 |
Hashes for fast_matrix_market-1.4.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b524b3620fa4f42e031d8c1320a40ddee90503c7ec5bb7e2bb2e03274aa44576 |
|
MD5 | 231bbac33823fa4d6394b1c8f2fe9201 |
|
BLAKE2b-256 | 883b4918e69fd1cf272d9020b973910d82abd9394540b2f1055ad2b8c485f04a |
Hashes for fast_matrix_market-1.4.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4052dd600f3d1d0b42189a1878d37422d4c4575f4667b34330a594b0645f0b42 |
|
MD5 | dd2870688e59901e6437a7470ca1b673 |
|
BLAKE2b-256 | aee62684fc4725fe0db78065caf78582199808783258f88673fcf4a9878be83c |
Hashes for fast_matrix_market-1.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d274c80364f7ab17c6794b063a3f87d0005c3086b5e257fdec6755d9efc861dc |
|
MD5 | a9bde7e074cfdce8c04462d87d956898 |
|
BLAKE2b-256 | 363ed658ffef4c86cb39eca6beb61696d6a8b6e3dbb71b81d6c89ee7c64f99f5 |
Hashes for fast_matrix_market-1.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3653f84de3ebe0acd7f6bbb53c6f6ed793f0604cd32ba198892cd1c0e60dd468 |
|
MD5 | 410b784b85a40fdee9fffaeb412b8045 |
|
BLAKE2b-256 | 30ae0dd1762f12d0be80c499b2f6bcc0d13a14a8158f5b96235a79789c4fc760 |
Hashes for fast_matrix_market-1.4.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3889049c5c58eca5d484422c7199d7a8c17c92816d2354eb48c9038999c2074 |
|
MD5 | 2f94115502db35db37842c9dd3ef7e4e |
|
BLAKE2b-256 | 7fa38763416820e9dcbbaa6a6f61ff1566ef418bc668653d15fa38585233564e |
Hashes for fast_matrix_market-1.4.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 141dfc6a51b2a6fd1ccb9b41244064ed92d9c4d6cabaaf0282443cc68877a85e |
|
MD5 | 0375262081c0120cff077c3b5b97313d |
|
BLAKE2b-256 | 40d8600339628ef5ce1555978a1dce17c8c8590721bff40597f9b2b1f2970527 |
Hashes for fast_matrix_market-1.4.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d56d15e72021e4ce429fdcb2c1d15ec961a1ee4d06717316571f01f69ea9a3f8 |
|
MD5 | 3d40aa5dfaebbaa655b3c67f49c84d9d |
|
BLAKE2b-256 | f60c9d869a53a544ce0e7f31a190a9cbcca39ccd1c0914a55b372025fc043023 |
Hashes for fast_matrix_market-1.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f052ade2342e7f7ed973728db3de587f74cab427118030a0f8c6a32164a84478 |
|
MD5 | 69465b2f8c6d0708cda7ceaa2e90e198 |
|
BLAKE2b-256 | ab936a0a1b345e0db331bd0d43cd2ef30dd046d2b448598331112baf34505ffc |
Hashes for fast_matrix_market-1.4.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5e6f7f7fe3d3b79535f5ed1568bae678277d68c016737b03cc9a58521b1b947 |
|
MD5 | d7d7fec011523c3729f2267f2e9bd6ad |
|
BLAKE2b-256 | 3cabc415974e844dae2a3850296121b2c6d3957bdbd1b929c92030b52150b2c4 |
Hashes for fast_matrix_market-1.4.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b422896960b046e1e9e09286bb1071ad4c5775b35d2da5cb0a604b4da0eef2e2 |
|
MD5 | ae90191b274cf4242a2f0d5b1b2800c9 |
|
BLAKE2b-256 | 919f8e4f36bdb7b976460e8793ae2257aa85ae7916bde533e5da551f44629091 |
Hashes for fast_matrix_market-1.4.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae6c2167b3f55f54975bab7fb241c3b4076386fb4baf0dad7f79348606fdd687 |
|
MD5 | e44514257db3b5741761971e3a4bb066 |
|
BLAKE2b-256 | 18a8867f1ddf7eac4f081974264215869588521bee8ca997c8394197dd4d9b6d |
Hashes for fast_matrix_market-1.4.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c95f4c35e4d94c344afe273c4f1a0138abd6308955533b977dc69ad00cf768d |
|
MD5 | 0e32c276bc7cb6cec562df42850a09ab |
|
BLAKE2b-256 | fc34347a52142d34c4ac47ded235606305e9a412582d32ee2d0fe83e3532b9a2 |
Hashes for fast_matrix_market-1.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23b731a1d3621980e11ca67d9f01b891d4ebdeab2668e0180d913d7904d0cedc |
|
MD5 | b89014103238364d33e47026ec8c1159 |
|
BLAKE2b-256 | 2d55d227ce93a911862bb59d2b08921e8993bf014bda36e3d4bba4666db636a5 |
Hashes for fast_matrix_market-1.4.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd89a54e33c0c712e63a9e78041a0a4d8c4e9b2e6b4bca03cab265a5805c7c24 |
|
MD5 | ac55c35fd683bf3d152f820a84f0efd4 |
|
BLAKE2b-256 | 0122a30d4d172a16a1bc0bda78e4e8c2fe057a243f3521fe1a0d52aae2063333 |
Hashes for fast_matrix_market-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8df9b7fa29c509bf45d6c5a8cf6e83e013da3841d59cbb62afbf4f4892268bd |
|
MD5 | f4342b2cdb53c77bac957aa8e4c34d2c |
|
BLAKE2b-256 | d044d8cd2db94964b89f2e87a11e6ddba3f2febfb7aaefea9c4c6b43b2a3d200 |
Hashes for fast_matrix_market-1.4.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 741de8c4b51d666fedd7b4523eb5233270c48c36bf98180c6bd5008c8ed835fc |
|
MD5 | ac16178d2ba31576e7032c944c610c0d |
|
BLAKE2b-256 | 0cd86e717ae79af432d4fef882b1ce49ec4a8554d7ddcd2a390a87056eb9aece |
Hashes for fast_matrix_market-1.4.0-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c814140600c3e5f8b04dc6607331c42a6d395abf5fcf2401342a0c6d4f5374 |
|
MD5 | 991862e68b564d1e9e5833643123957d |
|
BLAKE2b-256 | 0bdc415580ecb1083ad40c43f180ae5844aecd0005b24416921e972b60052de4 |
Hashes for fast_matrix_market-1.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1bacab3b169f4e3af4437914e69b10dc4a4216a4b732bef7b1ed39c31168ca |
|
MD5 | 606b50b6582c8d0c7aad064734584173 |
|
BLAKE2b-256 | ecb4d6a0d78a3cfff5353ec28562306e50778ced9559f0be3413cf1347841191 |
Hashes for fast_matrix_market-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44de826fe81efb691c26d9d306731e90bbb340da81430a1185b21610daeb9a8c |
|
MD5 | e116209ce702c86a1e3255092d1e94fd |
|
BLAKE2b-256 | e2f3856522114de257fd1e8b5e0f459f6c3210d1ec6a8b7164a168697aa7a76a |