summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-10-15 10:13:24 +0000
committerAlberto Ruiz <aruiz@um.es>2009-10-15 10:13:24 +0000
commit4863cdb1a7495547f05e068f3f8228dae4e57f1f (patch)
tree6ceefcebc1916250909a49931bfb22705bc7fbcb
parent026f20453ff3c8981ef6cab2d5d865837977b78d (diff)
NFData instances
-rw-r--r--examples/parallel.hs7
-rw-r--r--hmatrix.cabal13
-rw-r--r--lib/Numeric/LinearAlgebra/Instances.hs8
3 files changed, 22 insertions, 6 deletions
diff --git a/examples/parallel.hs b/examples/parallel.hs
index dfbfd88..8653bc3 100644
--- a/examples/parallel.hs
+++ b/examples/parallel.hs
@@ -1,14 +1,17 @@
1-- $ runhaskell parallel.hs 2000
2
1import System(getArgs) 3import System(getArgs)
2import Numeric.LinearAlgebra 4import Numeric.LinearAlgebra
3import Control.Parallel.Strategies 5import Control.Parallel.Strategies
4import System.Time 6import System.Time
5 7
6inParallel = parMap rwhnf id 8inParallel = parMap rnf id
9-- rwhnf also works in this case
7 10
11-- matrix product decomposed into p parallel subtasks
8parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] 12parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ]
9 where ys = splitColumns p y 13 where ys = splitColumns p y
10 14
11
12main = do 15main = do
13 n <- (read . head) `fmap` getArgs 16 n <- (read . head) `fmap` getArgs
14 let m = ident n :: Matrix Double 17 let m = ident n :: Matrix Double
diff --git a/hmatrix.cabal b/hmatrix.cabal
index 44fdd95..c99d3cb 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.5.2.3 2Version: 0.6.0.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -64,11 +64,16 @@ flag unsafe
64 64
65library 65library
66 if flag(splitBase) 66 if flag(splitBase)
67 build-depends: base >= 3 && < 5, array, QuickCheck, HUnit, storable-complex, process 67 build-depends: base >= 3 && < 5, array
68 else 68 else
69 build-depends: base < 3, QuickCheck, HUnit, storable-complex, process 69 build-depends: base < 3
70
71 Build-Depends: haskell98,
72 QuickCheck, HUnit,
73 storable-complex,
74 process,
75 parallel
70 76
71 Build-Depends: haskell98
72 Extensions: ForeignFunctionInterface, 77 Extensions: ForeignFunctionInterface,
73 CPP 78 CPP
74 79
diff --git a/lib/Numeric/LinearAlgebra/Instances.hs b/lib/Numeric/LinearAlgebra/Instances.hs
index 79a8990..3122a3d 100644
--- a/lib/Numeric/LinearAlgebra/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Instances.hs
@@ -27,6 +27,7 @@ import Data.List(transpose,intersperse)
27import Foreign(Storable) 27import Foreign(Storable)
28import Data.Monoid 28import Data.Monoid
29import Data.Packed.Internal.Vector 29import Data.Packed.Internal.Vector
30import Control.Parallel.Strategies
30 31
31------------------------------------------------------------------ 32------------------------------------------------------------------
32 33
@@ -196,3 +197,10 @@ instance (Storable a) => Monoid (Vector a) where
196 where j [] = mempty 197 where j [] = mempty
197 j l = join l 198 j l = join l
198 199
200---------------------------------------------------------------
201
202instance (NFData a, Storable a) => NFData (Vector a) where
203 rnf = rnf . (@>0)
204
205instance (NFData a, Element a) => NFData (Matrix a) where
206 rnf = rnf . flatten