summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--hmatrix.cabal6
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs70
3 files changed, 77 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index f786fdf..07835d4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
10.8.1.0
2=======
3
4- runBenchmarks
5
10.8.0.0 60.8.0.0
2======= 7=======
3 8
diff --git a/hmatrix.cabal b/hmatrix.cabal
index 1b077e3..77a37bb 100644
--- a/hmatrix.cabal
+++ b/hmatrix.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix 1Name: hmatrix
2Version: 0.8.0.0 2Version: 0.8.1.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -64,11 +64,11 @@ flag unsafe
64 64
65library 65library
66 if flag(splitBase) 66 if flag(splitBase)
67 build-depends: base >= 3 && < 5, array 67 build-depends: base >= 3 && < 5, array < 0.3.0
68 else 68 else
69 build-depends: base < 3 69 build-depends: base < 3
70 70
71 Build-Depends: haskell98, 71 Build-Depends: haskell98 < 1.0.1.1,
72 QuickCheck, HUnit, 72 QuickCheck, HUnit,
73 storable-complex, 73 storable-complex,
74 process 74 process
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.
17module Numeric.LinearAlgebra.Tests( 17module 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')
31import Numeric.GSL hiding (sin,cos,exp,choose) 31import Numeric.GSL hiding (sin,cos,exp,choose)
32import Prelude hiding ((^)) 32import Prelude hiding ((^))
33import qualified Prelude 33import qualified Prelude
34import System.CPUTime
35import Text.Printf
36
34#include "Tests/quickCheckCompat.h" 37#include "Tests/quickCheckCompat.h"
35 38
36a ^ b = a Prelude.^ (b :: Int) 39a ^ 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.
296runBenchmarks :: IO ()
297runBenchmarks = do
298 multBench
299 svdBench
300 eigBench
301 putStrLn ""
302
303--------------------------------
304
305time 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
315manymult 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
326multBench = 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
336eigBench = 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
347svdBench = 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)