diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-10-15 10:13:24 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-10-15 10:13:24 +0000 |
commit | 4863cdb1a7495547f05e068f3f8228dae4e57f1f (patch) | |
tree | 6ceefcebc1916250909a49931bfb22705bc7fbcb | |
parent | 026f20453ff3c8981ef6cab2d5d865837977b78d (diff) |
NFData instances
-rw-r--r-- | examples/parallel.hs | 7 | ||||
-rw-r--r-- | hmatrix.cabal | 13 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Instances.hs | 8 |
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 | |||
1 | import System(getArgs) | 3 | import System(getArgs) |
2 | import Numeric.LinearAlgebra | 4 | import Numeric.LinearAlgebra |
3 | import Control.Parallel.Strategies | 5 | import Control.Parallel.Strategies |
4 | import System.Time | 6 | import System.Time |
5 | 7 | ||
6 | inParallel = parMap rwhnf id | 8 | inParallel = parMap rnf id |
9 | -- rwhnf also works in this case | ||
7 | 10 | ||
11 | -- matrix product decomposed into p parallel subtasks | ||
8 | parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] | 12 | parMul p x y = fromBlocks [ inParallel ( map (x <>) ys ) ] |
9 | where ys = splitColumns p y | 13 | where ys = splitColumns p y |
10 | 14 | ||
11 | |||
12 | main = do | 15 | main = 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 @@ | |||
1 | Name: hmatrix | 1 | Name: hmatrix |
2 | Version: 0.5.2.3 | 2 | Version: 0.6.0.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -64,11 +64,16 @@ flag unsafe | |||
64 | 64 | ||
65 | library | 65 | library |
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) | |||
27 | import Foreign(Storable) | 27 | import Foreign(Storable) |
28 | import Data.Monoid | 28 | import Data.Monoid |
29 | import Data.Packed.Internal.Vector | 29 | import Data.Packed.Internal.Vector |
30 | import 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 | |||
202 | instance (NFData a, Storable a) => NFData (Vector a) where | ||
203 | rnf = rnf . (@>0) | ||
204 | |||
205 | instance (NFData a, Element a) => NFData (Matrix a) where | ||
206 | rnf = rnf . flatten | ||