Feedback on MatrixMarket I/O

Issue #449 new
Adam Lugowski created an issue

Hi,

I needed to load MatrixMarket .mtx files into Blaze sparse matrix and couldn't find a method to do so. So I wrote a Blaze binding for the generic fast_matrix_market library. I find Blaze is much more useful when I can get data in and out ;)

The usage is straight forward, see https://github.com/alugowski/fast_matrix_market/blob/main/README.Blaze.md

I'm writing for two reasons. First, is this something that other Blaze users would find useful?

Second, asking for verification that I used the most efficient approaches to construct, populate, and read each datastructure. I do have unit tests that check all the combinations against each other and this code passes with flying colors, but I don't know what I don't know.

I support all four combinations of sparse/dense matrices/vectors, both for reading and writing to a MatrixMarket file.
For sparse matrices/vectors I use append() for construction and iterators for reads. For dense matrices/vectors I use operator() for both. Is that reasonable?

Is std::enable_if<blaze::IsSparseMatrix_v<MATRIX_TYPE>> a good way to distinguish sparse/dense? (usage link: https://github.com/alugowski/fast_matrix_market/blob/4e12cc7391e6b210748bc8a1a6817a3f11985f19/include/fast_matrix_market/app/Blaze.hpp#L15))

My sparse matrix construction code: https://github.com/alugowski/fast_matrix_market/blob/4e12cc7391e6b210748bc8a1a6817a3f11985f19/include/fast_matrix_market/app/Blaze.hpp#L44
First I read the .mtx file into row/column/value vectors, sort according to the storage order of the user's matrix, then construct using append().
The docs can be a bit ambiguous on naming the indices. I.e. sometimes they'll say "row" when they mean "row if rowMajor" and such. I believe what I have is correct but would appreciate feedback.

Thanks!

Comments (1)

  1. Klaus Iglberger

    Hi Adam!

    Thank you very much for you initiative to introduce Matrix Market support to Blaze. I believe that this will be useful for many Blaze users. Therefore I’ve added your repo as a Blaze project on the Blaze main page.

    Is std::enable_if<blaze::IsSparseMatrix_v<MATRIX_TYPE>> a good way to distinguish sparse/dense?

    Yes, this is a reasonable way. Alternatively you can write functions that take a blaze::SparseMatrix as function parameter, as all sparse matrices in Blaze derive from this (CRTP) base class.

    The docs can be a bit ambiguous on naming the indices.

    The documentation of Blaze is very concise about rows and columns. Whenever the documentation speaks about a ‘row’ it really means a row, regardless of whether the matrix is stored in row-major or column-major fashion.

    In case you are wondering about how to set up a sparse matrix efficiently, please see the FAQ.

    Thanks again for your initiative,

    Best regards,

    Klaus!

  2. Log in to comment