eminem
Parse Matrix Market files in C++
|
The eminem library implements parsers for Matrix Market (*.mm
/*.mtx
) files. We support matrix or vector objects, coordinate or array formats, and all the different fields (integer, real, complex and pattern). We support reading from text files, Gzip-compressed files, as well as in-memory buffers. Users can supply their own functions to process each line on the fly, based on the information in the banner and size lines.
We first create a Parser
instance, in this case from a text file. We also support parsing of Gzip-compressed files, buffers, or any input source of bytes compatible with the byteme interfaces.
We scan through the preamble, which contains the banner and the size lines. The type of the data field in the banner will determine which scanning function to use. The size lines can also help with pre-allocation of memory to store the scanning output, if necessary.
Finally, we scan through the actual data lines, providing a lambda or functor to process each row/column/value triplet as it is parsed. Note that the row/column indices are 1-based when they are passed to the lambda.
Check out the reference documentation for more details.
FetchContent
If you're using CMake, you just need to add something like this to your CMakeLists.txt
:
Then you can link to tatami to make the headers available during compilation:
By default, this will use FetchContent
to fetch all external dependencies. Applications are advised to pin the versions of all dependencies themselves - see extern/CMakeLists.txt
for suggested versions. If you want to install them manually, use -DEMINEM_FETCH_EXTERN=OFF
.
find_package()
You can install the library by cloning a suitable version of this repository and running the following commands:
Then you can use find_package()
as usual:
Again, this will use FetchContent
to fetch dependencies, see comments above.
If you're not using CMake, the simple approach is to just copy the files the include/
subdirectory - either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I
. This also requires the external dependencies listed in extern/CMakeLists.txt
as well as Zlib.