Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ocramz/matrix-market-attoparsec
Attoparsec parsers for the NIST Matrix Market format
https://github.com/ocramz/matrix-market-attoparsec
matrix parser-combinators parser-library sparse-matrices sparse-matrix
Last synced: 22 days ago
JSON representation
Attoparsec parsers for the NIST Matrix Market format
- Host: GitHub
- URL: https://github.com/ocramz/matrix-market-attoparsec
- Owner: ocramz
- License: bsd-2-clause
- Created: 2017-01-14T22:37:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-01-19T10:08:38.000Z (almost 5 years ago)
- Last Synced: 2024-05-01T23:25:13.412Z (6 months ago)
- Topics: matrix, parser-combinators, parser-library, sparse-matrices, sparse-matrix
- Language: Haskell
- Size: 1000 KB
- Stars: 7
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.markdown
- License: LICENSE
Awesome Lists containing this project
README
# matrix-market-attoparsec
[![Build Status](https://travis-ci.org/ocramz/matrix-market-attoparsec.png)](https://travis-ci.org/ocramz/matrix-market-attoparsec)
Attoparsec parser for the NIST Matrix Market format [0].
The library also contains functions for serializing matrix data to text file.
## User guide
The module `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 @readMatrix'@, @readArray'@, @writeMatrix'@ and @writeArray'@ that do not touch the filesystem but (de-)serialize from/to lazy ByteString.
### Naming convention
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.## Testing
`test/LibSpec.hs` contains a simple read/write/read sanity test for the included Matrix Marked data files (`fidapm05.mtx` and `fidapm05_rhs1.mtx`):
m0 <- readMatrix fname -- load original
writeMatrix ftemp m0 -- save as temp
m1 <- readMatrix ftemp -- load temp
m0 `shouldBe` m1 -- compare temp with original## References
[0] [http://math.nist.gov/MatrixMarket/](http://math.nist.gov/MatrixMarket/)