summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--THANKS3
-rw-r--r--hmatrix.cabal5
-rw-r--r--lib/Data/Packed/Matrix.hs21
-rw-r--r--lib/Data/Packed/Vector.hs19
4 files changed, 45 insertions, 3 deletions
diff --git a/THANKS b/THANKS
index 8797578..d8a9e0e 100644
--- a/THANKS
+++ b/THANKS
@@ -73,5 +73,6 @@ and all the people in the Haskell mailing lists for their help.
73- Max Suica simplified the installation on Windows and improved the instructions. 73- Max Suica simplified the installation on Windows and improved the instructions.
74 74
75- Vivian McPhail fixed configure.hs to allow non-root user installation in 75- Vivian McPhail fixed configure.hs to allow non-root user installation in
76 case that /tmp is not writable. 76 case that /tmp is not writable. He also contributed Binary instances for
77 Vector and Matrix.
77 78
diff --git a/hmatrix.cabal b/hmatrix.cabal
index cbf4a55..e7a64c8 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.9.3.0 2Version: 0.10.0.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -74,7 +74,8 @@ library
74 Build-Depends: base >= 4 && < 5, 74 Build-Depends: base >= 4 && < 5,
75 array, 75 array,
76 storable-complex, 76 storable-complex,
77 process 77 process,
78 ghc-binary
78 79
79 Extensions: ForeignFunctionInterface, 80 Extensions: ForeignFunctionInterface,
80 CPP 81 CPP
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)