diff options
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra')
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests.hs | 42 |
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((***)) | |||
43 | import Debug.Trace | 43 | import Debug.Trace |
44 | import Control.Monad(when) | 44 | import Control.Monad(when) |
45 | 45 | ||
46 | import Data.Packed.ST | ||
47 | |||
46 | import Test.QuickCheck(Arbitrary,arbitrary,coarbitrary,choose,vector | 48 | import 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 () | |||
622 | runBenchmarks = do | 624 | runBenchmarks = 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 | ||
644 | timeR 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 | ||
643 | manymult n = foldl1' (<>) (map rot2 angles) where | 654 | manymult 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 | ||
667 | manyvec0 xs = sum $ map (\x -> x + x**2 + x**3) xs | ||
668 | manyvec1 xs = sumElements $ fromRows $ map (\x -> fromList [x,x**2,x**3]) xs | ||
669 | manyvec5 xs = sumElements $ fromRows $ map (\x -> vec3 x (x**2) (x**3)) xs | ||
670 | |||
671 | |||
672 | manyvec2 xs = sum $ map (\x -> sqrt(x^2 + (x**2)^2 +(x**3)^2)) xs | ||
673 | manyvec3 xs = sum $ map (pnorm PNorm2 . (\x -> fromList [x,x**2,x**3])) xs | ||
674 | |||
675 | manyvec4 xs = sum $ map (pnorm PNorm2 . (\x -> vec3 x (x**2) (x**3))) xs | ||
676 | |||
677 | vec3 :: Double -> Double -> Double -> Vector Double | ||
678 | vec3 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 | |||
685 | mkVecBench = 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 | |||
656 | subBench = do | 698 | subBench = 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)) |