summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2012-03-11 19:48:47 +0100
committerAlberto Ruiz <aruiz@um.es>2012-03-11 19:48:47 +0100
commit56ebc37b39c99e4ee97483b6d37d4a0bec880c03 (patch)
tree083e5fd6e04fbbdce4ac063bdcf3eae75b719668
parent179d1f01d43fbf565780ad4af38907c62abf11e5 (diff)
mkVecBench
-rw-r--r--packages/tests/hmatrix-tests.cabal2
-rw-r--r--packages/tests/src/Numeric/LinearAlgebra/Tests.hs42
2 files changed, 43 insertions, 1 deletions
diff --git a/packages/tests/hmatrix-tests.cabal b/packages/tests/hmatrix-tests.cabal
index 9f7bcdc..d1f449b 100644
--- a/packages/tests/hmatrix-tests.cabal
+++ b/packages/tests/hmatrix-tests.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix-tests 1Name: hmatrix-tests
2Version: 0.1.0.0 2Version: 0.1.1
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
index 8d402d0..7c41209 100644
--- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
+++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs
@@ -43,6 +43,8 @@ import Control.Arrow((***))
43import Debug.Trace 43import Debug.Trace
44import Control.Monad(when) 44import Control.Monad(when)
45 45
46import Data.Packed.ST
47
46import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector 48import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector
47 ,sized,classify,Testable,Property 49 ,sized,classify,Testable,Property
48 ,quickCheckWithResult,maxSize,stdArgs,shrink) 50 ,quickCheckWithResult,maxSize,stdArgs,shrink)
@@ -622,6 +624,7 @@ runBenchmarks :: IO ()
622runBenchmarks = do 624runBenchmarks = do
623 solveBench 625 solveBench
624 subBench 626 subBench
627 mkVecBench
625 multBench 628 multBench
626 cholBench 629 cholBench
627 svdBench 630 svdBench
@@ -638,6 +641,14 @@ time msg act = do
638 printf "%6.2f s CPU\n" $ (fromIntegral (t1 - t0) / (10^12 :: Double)) :: IO () 641 printf "%6.2f s CPU\n" $ (fromIntegral (t1 - t0) / (10^12 :: Double)) :: IO ()
639 return () 642 return ()
640 643
644timeR msg act = do
645 putStr (msg++" ")
646 t0 <- getCPUTime
647 putStr (show act)
648 t1 <- getCPUTime
649 printf "%6.2f s CPU\n" $ (fromIntegral (t1 - t0) / (10^12 :: Double)) :: IO ()
650 return ()
651
641-------------------------------- 652--------------------------------
642 653
643manymult n = foldl1' (<>) (map rot2 angles) where 654manymult n = foldl1' (<>) (map rot2 angles) where
@@ -653,6 +664,37 @@ multb n = foldl1' (<>) (replicate (10^6) (ident n :: Matrix Double))
653 664
654-------------------------------- 665--------------------------------
655 666
667manyvec0 xs = sum $ map (\x -> x + x**2 + x**3) xs
668manyvec1 xs = sumElements $ fromRows $ map (\x -> fromList [x,x**2,x**3]) xs
669manyvec5 xs = sumElements $ fromRows $ map (\x -> vec3 x (x**2) (x**3)) xs
670
671
672manyvec2 xs = sum $ map (\x -> sqrt(x^2 + (x**2)^2 +(x**3)^2)) xs
673manyvec3 xs = sum $ map (pnorm PNorm2 . (\x -> fromList [x,x**2,x**3])) xs
674
675manyvec4 xs = sum $ map (pnorm PNorm2 . (\x -> vec3 x (x**2) (x**3))) xs
676
677vec3 :: Double -> Double -> Double -> Vector Double
678vec3 a b c = runSTVector $ do
679 v <- newUndefinedVector 3
680 writeVector v 0 a
681 writeVector v 1 b
682 writeVector v 2 c
683 return v
684
685mkVecBench = do
686 let n = 1000000
687 xs = toList $ linspace n (0,1::Double)
688 putStr "\neval data... "; print (sum xs)
689 timeR "listproc " $ manyvec0 xs
690 timeR "fromList matrix " $ manyvec1 xs
691 timeR "vec3 matrix " $ manyvec5 xs
692 timeR "listproc norm " $ manyvec2 xs
693 timeR "norm fromList " $ manyvec3 xs
694 timeR "norm vec3 " $ manyvec4 xs
695
696--------------------------------
697
656subBench = do 698subBench = do
657 putStrLn "" 699 putStrLn ""
658 let g = foldl1' (.) (replicate (10^5) (\v -> subVector 1 (dim v -1) v)) 700 let g = foldl1' (.) (replicate (10^5) (\v -> subVector 1 (dim v -1) v))