diff options
author | Alberto Ruiz <aruiz@um.es> | 2009-12-30 12:35:22 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2009-12-30 12:35:22 +0000 |
commit | f2670646b35f736778ce32cd0a32b8953b6c369b (patch) | |
tree | e6504b19b95cad7a0f096d3ee0b97d3b37691040 /lib | |
parent | 036f0f19c473cb58a1f7330a481d0e8f705ac452 (diff) |
runBenchmarks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Numeric/LinearAlgebra/Tests.hs | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs index 8c55486..9557ac3 100644 --- a/lib/Numeric/LinearAlgebra/Tests.hs +++ b/lib/Numeric/LinearAlgebra/Tests.hs | |||
@@ -17,7 +17,7 @@ Some tests. | |||
17 | module Numeric.LinearAlgebra.Tests( | 17 | module Numeric.LinearAlgebra.Tests( |
18 | -- module Numeric.LinearAlgebra.Tests.Instances, | 18 | -- module Numeric.LinearAlgebra.Tests.Instances, |
19 | -- module Numeric.LinearAlgebra.Tests.Properties, | 19 | -- module Numeric.LinearAlgebra.Tests.Properties, |
20 | qCheck, runTests | 20 | qCheck, runTests, runBenchmarks |
21 | --, runBigTests | 21 | --, runBigTests |
22 | ) where | 22 | ) where |
23 | 23 | ||
@@ -31,6 +31,9 @@ import Data.List(foldl1') | |||
31 | import Numeric.GSL hiding (sin,cos,exp,choose) | 31 | import Numeric.GSL hiding (sin,cos,exp,choose) |
32 | import Prelude hiding ((^)) | 32 | import Prelude hiding ((^)) |
33 | import qualified Prelude | 33 | import qualified Prelude |
34 | import System.CPUTime | ||
35 | import Text.Printf | ||
36 | |||
34 | #include "Tests/quickCheckCompat.h" | 37 | #include "Tests/quickCheckCompat.h" |
35 | 38 | ||
36 | a ^ b = a Prelude.^ (b :: Int) | 39 | a ^ b = a Prelude.^ (b :: Int) |
@@ -286,3 +289,68 @@ makeUnitary v | realPart n > 1 = v */ n | |||
286 | -- -- | Some additional tests on big matrices. They take a few minutes. | 289 | -- -- | Some additional tests on big matrices. They take a few minutes. |
287 | -- runBigTests :: IO () | 290 | -- runBigTests :: IO () |
288 | -- runBigTests = undefined | 291 | -- runBigTests = undefined |
292 | |||
293 | -------------------------------------------------------------------------------- | ||
294 | |||
295 | -- | Performance measurements. | ||
296 | runBenchmarks :: IO () | ||
297 | runBenchmarks = do | ||
298 | multBench | ||
299 | svdBench | ||
300 | eigBench | ||
301 | putStrLn "" | ||
302 | |||
303 | -------------------------------- | ||
304 | |||
305 | time msg act = do | ||
306 | putStr (msg++" ") | ||
307 | t0 <- getCPUTime | ||
308 | act `seq` putStr " " | ||
309 | t1 <- getCPUTime | ||
310 | printf "%5.1f s CPU\n" $ (fromIntegral (t1 - t0) / (10^12 :: Double)) :: IO () | ||
311 | return () | ||
312 | |||
313 | -------------------------------- | ||
314 | |||
315 | manymult n = foldl1' (<>) (map rot2 angles) where | ||
316 | angles = toList $ linspace n (0,1) | ||
317 | rot2 :: Double -> Matrix Double | ||
318 | rot2 a = (3><3) [ c,0,s | ||
319 | , 0,1,0 | ||
320 | ,-s,0,c ] | ||
321 | where c = cos a | ||
322 | s = sin a | ||
323 | |||
324 | -------------------------------- | ||
325 | |||
326 | multBench = do | ||
327 | let a = ident 1000 :: Matrix Double | ||
328 | let b = ident 2000 :: Matrix Double | ||
329 | a `seq` b `seq` putStrLn "" | ||
330 | time "product of 1M different 3x3 matrices" (manymult (10^6)) | ||
331 | time "product (1000 x 1000)<>(1000 x 1000)" (a<>a) | ||
332 | time "product (2000 x 2000)<>(2000 x 2000)" (b<>b) | ||
333 | |||
334 | -------------------------------- | ||
335 | |||
336 | eigBench = do | ||
337 | let m = reshape 1000 (randomVector 777 Uniform (1000*1000)) | ||
338 | s = m + trans m | ||
339 | m `seq` s `seq` putStrLn "" | ||
340 | time "eigenvalues symmetric 1000x1000" (eigenvaluesSH' m) | ||
341 | time "eigenvectors symmetric 1000x1000" (snd $ eigSH' m) | ||
342 | time "eigenvalues general 1000x1000" (eigenvalues m) | ||
343 | time "eigenvectors general 1000x1000" (snd $ eig m) | ||
344 | |||
345 | -------------------------------- | ||
346 | |||
347 | svdBench = do | ||
348 | let a = reshape 500 (randomVector 777 Uniform (3000*500)) | ||
349 | b = reshape 1000 (randomVector 777 Uniform (1000*1000)) | ||
350 | fv (_,_,v) = v@@>(0,0) | ||
351 | a `seq` b `seq` putStrLn "" | ||
352 | time "singular values 3000x500" (singularValues a) | ||
353 | time "thin svd 3000x500" (fv $ thinSVD a) | ||
354 | time "full svd 3000x500" (fv $ svd a) | ||
355 | time "singular values 1000x1000" (singularValues b) | ||
356 | time "full svd 1000x1000" (fv $ svd b) | ||