summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-11-04 09:32:35 +0000
committerAlberto Ruiz <aruiz@um.es>2008-11-04 09:32:35 +0000
commit02805ad64715373347b34bac2f75cbb866563ba2 (patch)
tree4eeb137ce0232d57ce98c0a0ced8fffe7baf7f99 /examples
parent86c7aed1de8efe5988f994867d35addb6b62a655 (diff)
multiply/trans ok
Diffstat (limited to 'examples')
-rw-r--r--examples/benchmarks.hs25
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
21main = sequence_ [bench1,bench2,bench3,bench4] 21main = sequence_ [bench1,bench2,bench3,bench4,bench5 1000000 3]
22 22
23w :: Vector Double 23w :: Vector Double
24w = constant 1 5000000 24w = 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
54bench2 = do 57bench2 = 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
133op1 a b = a <> trans b
134
135op2 a b = a + trans b
136
137timep = time . print . vectorMax . flatten
138
139bench5 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