diff options
author | Alberto Ruiz <aruiz@um.es> | 2008-11-04 09:32:35 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2008-11-04 09:32:35 +0000 |
commit | 02805ad64715373347b34bac2f75cbb866563ba2 (patch) | |
tree | 4eeb137ce0232d57ce98c0a0ced8fffe7baf7f99 /examples/benchmarks.hs | |
parent | 86c7aed1de8efe5988f994867d35addb6b62a655 (diff) |
multiply/trans ok
Diffstat (limited to 'examples/benchmarks.hs')
-rw-r--r-- | examples/benchmarks.hs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs index 78c1e5f..7ba15aa 100644 --- a/examples/benchmarks.hs +++ b/examples/benchmarks.hs | |||
@@ -18,7 +18,7 @@ time act = do | |||
18 | 18 | ||
19 | -------------------------------------------------------------------------------- | 19 | -------------------------------------------------------------------------------- |
20 | 20 | ||
21 | main = sequence_ [bench1,bench2,bench3,bench4] | 21 | main = sequence_ [bench1,bench2,bench3,bench4,bench5 1000000 3] |
22 | 22 | ||
23 | w :: Vector Double | 23 | w :: Vector Double |
24 | w = constant 1 5000000 | 24 | w = constant 1 5000000 |
@@ -49,6 +49,9 @@ innerH u v = go (d - 1) 0 | |||
49 | go 0 s = s + (u @> 0) * (v @> 0) | 49 | go 0 s = s + (u @> 0) * (v @> 0) |
50 | go !j !s = go (j - 1) (s + (u @> j) * (v @> j)) | 50 | go !j !s = go (j - 1) (s + (u @> j) * (v @> j)) |
51 | 51 | ||
52 | -- These functions are much faster if the library | ||
53 | -- is configured with -funsafe | ||
54 | |||
52 | -------------------------------------------------------------------------------- | 55 | -------------------------------------------------------------------------------- |
53 | 56 | ||
54 | bench2 = do | 57 | bench2 = do |
@@ -124,3 +127,23 @@ bench4 = do | |||
124 | let b = 2*a | 127 | let b = 2*a |
125 | print $ vectorMax $ flatten (a+b) -- evaluate it | 128 | print $ vectorMax $ flatten (a+b) -- evaluate it |
126 | time $ print $ vectorMax $ flatten $ linearSolve a b | 129 | time $ print $ vectorMax $ flatten $ linearSolve a b |
130 | |||
131 | -------------------------------------------------------------------------------- | ||
132 | |||
133 | op1 a b = a <> trans b | ||
134 | |||
135 | op2 a b = a + trans b | ||
136 | |||
137 | timep = time . print . vectorMax . flatten | ||
138 | |||
139 | bench5 n d = do | ||
140 | putStrLn "-------------------------------------------------------" | ||
141 | putStrLn "transpose in multiply" | ||
142 | let ms = replicate n ((ident d :: Matrix Double)) | ||
143 | let mz = replicate n (diag (constant (0::Double) d)) | ||
144 | timep $ foldl1' (<>) ms | ||
145 | timep $ foldl1' op1 ms | ||
146 | putStrLn "-------------------------------------------------------" | ||
147 | putStrLn "transpose in add" | ||
148 | timep $ foldl1' (+) ms | ||
149 | timep $ foldl1' op2 ms | ||