summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/Packed/Matrix.hs')
-rw-r--r--lib/Data/Packed/Matrix.hs21
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)
44import Data.List(transpose,intersperse) 44import Data.List(transpose,intersperse)
45import Data.Complex 45import Data.Complex
46 46
47import Data.Binary
48import Foreign.Storable
49import Control.Monad(replicateM)
50
51-------------------------------------------------------------------
52
53instance (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
48joinVert :: Element t => [Matrix t] -> Matrix t 69joinVert :: Element t => [Matrix t] -> Matrix t
49joinVert ms = case common cols ms of 70joinVert ms = case common cols ms of