summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Matrix.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-06-21 08:23:15 +0000
committerAlberto Ruiz <aruiz@um.es>2010-06-21 08:23:15 +0000
commitd18a86d37d55a39d4ec9b16397dd59f35aa13688 (patch)
tree1ed0ce908efc6a364398b0814692df9f04e894db /lib/Data/Packed/Matrix.hs
parentb830956a037b6122f83ed6117596b2ef510eb911 (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.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