After searching unsuccessfully for how to do this, I discovered that there's a Binary instance internal to hmatrix. The following code depends on hmatrix
, binary
, and bytestring
.
Last active
October 1, 2017 22:29
-
-
Save mhuesch/1fc67e6513d162625fc37c1bc89f6e39 to your computer and use it in GitHub Desktop.
Serialize/deserialize hmatrix matrices to/from a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Binary | |
import qualified Data.ByteString.Lazy as BS | |
import Numeric.LinearAlgebra | |
main = do | |
let testMatrix = matrix 3 [1..6] :: Matrix Double | |
bs = encode testMatrix | |
fp = "testMatrix.dat" | |
BS.writeFile fp bs | |
bs' <- BS.readFile fp | |
let testMatrix' = decode bs' :: Matrix Double | |
putStrLn $ "Matrices are equal? " ++ show (testMatrix == testMatrix') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment