summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Data/Packed/Matrix.hs21
-rw-r--r--lib/Data/Packed/Vector.hs19
2 files changed, 40 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
diff --git a/lib/Data/Packed/Vector.hs b/lib/Data/Packed/Vector.hs
index 472240c..f6b3fc6 100644
--- a/lib/Data/Packed/Vector.hs
+++ b/lib/Data/Packed/Vector.hs
@@ -29,6 +29,25 @@ import Data.Packed.Internal
29import Numeric.GSL.Vector 29import Numeric.GSL.Vector
30-- import Data.Packed.ST 30-- import Data.Packed.ST
31 31
32import Data.Binary
33import Foreign.Storable
34import Control.Monad(replicateM)
35
36-------------------------------------------------------------------
37
38instance (Binary a, Storable a) => Binary (Vector a) where
39 put v = do
40 let d = dim v
41 put d
42 mapM_ (\i -> put $ v @> i) [0..(d-1)]
43 get = do
44 d <- get
45 xs <- replicateM d get
46 return $ fromList xs
47
48-------------------------------------------------------------------
49
50
32{- | Creates a real vector containing a range of values: 51{- | Creates a real vector containing a range of values:
33 52
34@\> linspace 5 (-3,7) 53@\> linspace 5 (-3,7)