Parsing and serialization functions for the NIST Matrix Market format https://github.com/ocramz/matrix-market-attoparsec
|LTS Haskell 15.7:||0.1.1.3|
|Stackage Nightly 2020-04-08:||0.1.1.3|
|Latest on Hackage:||0.1.1.3|
Attoparsec parser for the NIST Matrix Market format .
The library also contains functions for serializing matrix data to text file.
Data.Matrix.MatrixMarket exports the user interface:
readMatrix :: FilePath -> IO (Matrix S.Scientific) readArray :: FilePath -> IO (Array S.Scientific) writeMatrix :: Show a => FilePath -> Matrix a -> IO () writeArray :: Show a => FilePath -> Array a -> IO ()
The first two functions contain the parsing logic, and make use of
scientific for parsing numerical data in scientific notation.
As of version 0.1.1 there are also intermediate functions
writeArray' that do not touch the filesystem but (de-)serialize from/to lazy ByteString.
We follow the MatrixMarket format definitions, by which a “Matrix” is sparse and stored in coordinate format (row, column, entry), whereas an “Array” is a dense grid of numbers, stored in column-oriented form. Algebraic vectors, such as the right-hand sides of equation systems, are stored as n-by-1 Arrays.
test/LibSpec.hs contains a simple read/write/read sanity test for the included Matrix Marked data files (
m0 <- readMatrix fname -- load original writeMatrix ftemp m0 -- save as temp m1 <- readMatrix ftemp -- load temp m0 `shouldBe` m1 -- compare temp with original
Expose writeArray’ and readArray’ as well
Add ExportError exception
Add MatrixMarket module from