diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Data/Packed/Matrix.hs | 21 | ||||
-rw-r--r-- | lib/Data/Packed/Vector.hs | 19 |
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) | |||
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 |
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 | |||
29 | import Numeric.GSL.Vector | 29 | import Numeric.GSL.Vector |
30 | -- import Data.Packed.ST | 30 | -- import Data.Packed.ST |
31 | 31 | ||
32 | import Data.Binary | ||
33 | import Foreign.Storable | ||
34 | import Control.Monad(replicateM) | ||
35 | |||
36 | ------------------------------------------------------------------- | ||
37 | |||
38 | instance (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) |