matrix-market-attoparsec 0.1.0.9 → 0.1.1.0
raw patch · 5 files changed
+29/−16 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Matrix.MatrixMarket: FileParseError :: String -> String -> ImportError
+ Data.Matrix.MatrixMarket: readMatrix' :: ByteString -> IO (Matrix Scientific)
+ Data.Matrix.MatrixMarket: writeMatrix' :: (MonadThrow m, Show b) => Matrix b -> m ByteString
Files
- CHANGELOG.markdown +5/−1
- matrix-market-attoparsec.cabal +1/−1
- src/Control/Exception/Common.hs +9/−1
- src/Data/Matrix/MatrixMarket.hs +3/−3
- src/Data/Matrix/MatrixMarket/Internal.hs +11/−10
CHANGELOG.markdown view
@@ -1,3 +1,7 @@+0.1.1.0++Add ExportError exception+ 0.1.0.1 -Added MatrixMarket module from `accelerate-examples` SMVM+Add MatrixMarket module from `accelerate-examples` SMVM
matrix-market-attoparsec.cabal view
@@ -1,5 +1,5 @@ name: matrix-market-attoparsec-version: 0.1.0.9+version: 0.1.1.0 synopsis: Parsing and serialization functions for the NIST Matrix Market format description: Parsing and serialization functions for the NIST Matrix Market format. homepage: https://github.com/ocramz/matrix-market-attoparsec
src/Control/Exception/Common.hs view
@@ -1,4 +1,5 @@ {-# language DeriveDataTypeable #-}+{-# language LambdaCase #-} module Control.Exception.Common where import Control.Exception@@ -8,5 +9,12 @@ data ImportError = FileParseError String String deriving (Eq, Typeable) instance Show ImportError where- show (FileParseError s s2) = unwords [s, ": File parse error:", s2]+ show = \case+ FileParseError s s2 -> unwords [s, ": File parse error:", s2] instance Exception ImportError++data ExportError = FormatExportNotSupported String String deriving (Eq, Typeable)+instance Show ExportError where+ show = \case+ FormatExportNotSupported s sty -> unwords [s, ":", sty, "format not supported"]+instance Exception ExportError
src/Data/Matrix/MatrixMarket.hs view
@@ -17,9 +17,9 @@ ----------------------------------------------------------------------------- module Data.Matrix.MatrixMarket (-- * Load- readMatrix, readArray,+ readMatrix, readMatrix', readArray, -- * Save- writeMatrix, writeArray,+ writeMatrix, writeMatrix', writeArray, -- Matrix(..), Array(..), Format (Coordinate, Array), Structure (General, Symmetric, Hermitian, Skew),@@ -29,6 +29,6 @@ -- ** Array-related dimArr, numDatArr, -- * Exceptions- ImportError) where+ ImportError(..)) where import Data.Matrix.MatrixMarket.Internal as M
src/Data/Matrix/MatrixMarket/Internal.hs view
@@ -23,7 +23,7 @@ Format (Coordinate, Array), Structure (General, Symmetric, Hermitian, Skew), nnz, dim, numDat, dimArr, numDatArr,- ImportError) where+ ImportError(..)) where @@ -40,7 +40,7 @@ import qualified Data.ByteString.Lazy as L import Control.Monad.Catch-import Control.Exception.Common+import Control.Exception.Common (ImportError(..), ExportError(..)) @@ -187,7 +187,7 @@ readMatrix :: FilePath -> IO (Matrix S.Scientific) readMatrix file = L.readFile file >>= readMatrix' --- | Load a matrix (sparse, i.e. in Coordinate format) from a bytestring.+-- | Load a matrix (sparse, i.e. in Coordinate format) from a lazy 'L.Bytestring'. readMatrix' :: L.ByteString -> IO (Matrix S.Scientific) readMatrix' chunks = case L.parse matrix chunks of@@ -238,18 +238,20 @@ -- | Serialize a sparse matrix in Coordinate format writeMatrix :: Show b => FilePath -> Matrix b -> IO ()-writeMatrix file = L.writeFile file . writeMatrix'+writeMatrix fp mat = do+ mbs <- writeMatrix' mat+ L.writeFile fp mbs -- | Serialize a sparse matrix in Coordinate format as a bytestring-writeMatrix' :: Show b => Matrix b -> L.ByteString+writeMatrix' :: (MonadThrow m, Show b) => Matrix b -> m L.ByteString writeMatrix' mat = case mat of (RMatrix d nz s dat) ->- matrixByteString d nz R s dat+ pure $ matrixByteString d nz R s dat (CMatrix d nz s dat) ->- matrixByteString d nz C s dat+ pure $ matrixByteString d nz C s dat (IntMatrix d nz s dat) ->- matrixByteString d nz I s dat- _ -> error "writeMatrix : PatternMatrix not implemented yet"+ pure $ matrixByteString d nz I s dat+ _ -> throwM (FormatExportNotSupported "writeMatrix" "PatternMatrix not implemented yet") where matrixByteString di nz t s d = L.concat [headerStr Coordinate t s,@@ -282,7 +284,6 @@ --- | helpers -- | Number of matrix nonzeros nnz :: Matrix t -> Int