diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-06-21 08:23:15 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-06-21 08:23:15 +0000 |
commit | d18a86d37d55a39d4ec9b16397dd59f35aa13688 (patch) | |
tree | 1ed0ce908efc6a364398b0814692df9f04e894db /lib/Data/Packed/Matrix.hs | |
parent | b830956a037b6122f83ed6117596b2ef510eb911 (diff) |
Binary instances for Vector and Matrix by Vivian McPhail
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Data/Packed/Matrix.hs b/lib/Data/Packed/Matrix.hs index 3147e13..0c21b97 100644 --- a/lib/Data/Packed/Matrix.hs +++ b/lib/Data/Packed/Matrix.hs | |||
@@ -44,6 +44,27 @@ import Text.Printf(printf) | |||
44 | import Data.List(transpose,intersperse) | 44 | import Data.List(transpose,intersperse) |
45 | import Data.Complex | 45 | import Data.Complex |
46 | 46 | ||
47 | import Data.Binary | ||
48 | import Foreign.Storable | ||
49 | import Control.Monad(replicateM) | ||
50 | |||
51 | ------------------------------------------------------------------- | ||
52 | |||
53 | instance (Binary a, Element a, Storable a) => Binary (Matrix a) where | ||
54 | put m = do | ||
55 | let r = rows m | ||
56 | let c = cols m | ||
57 | put r | ||
58 | put c | ||
59 | mapM_ (\i -> mapM_ (\j -> put $ m @@> (i,j)) [0..(c-1)]) [0..(r-1)] | ||
60 | get = do | ||
61 | r <- get | ||
62 | c <- get | ||
63 | xs <- replicateM r $ replicateM c get | ||
64 | return $ fromLists xs | ||
65 | |||
66 | ------------------------------------------------------------------- | ||
67 | |||
47 | -- | creates a matrix from a vertical list of matrices | 68 | -- | creates a matrix from a vertical list of matrices |
48 | joinVert :: Element t => [Matrix t] -> Matrix t | 69 | joinVert :: Element t => [Matrix t] -> Matrix t |
49 | joinVert ms = case common cols ms of | 70 | joinVert ms = case common cols ms of |