summaryrefslogtreecommitdiff
path: root/packages/tests/src/Numeric/LinearAlgebra
diff options
context:
space:
mode:
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra')
-rw-r--r--packages/tests/src/Numeric/LinearAlgebra/Tests.hs42
1 files changed, 42 insertions, 0 deletions
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))