diff options
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra/Tests.hs')
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests.hs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs index 2ff1580..30480d7 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs | |||
@@ -127,8 +127,8 @@ expmTest2 = expm nd2 :~15~: (2><2) | |||
127 | mbCholTest = utest "mbCholTest" (ok1 && ok2) where | 127 | mbCholTest = utest "mbCholTest" (ok1 && ok2) where |
128 | m1 = (2><2) [2,5,5,8 :: Double] | 128 | m1 = (2><2) [2,5,5,8 :: Double] |
129 | m2 = (2><2) [3,5,5,9 :: Complex Double] | 129 | m2 = (2><2) [3,5,5,9 :: Complex Double] |
130 | ok1 = mbCholSH m1 == Nothing | 130 | ok1 = mbChol (trustSym m1) == Nothing |
131 | ok2 = mbCholSH m2 == Just (chol m2) | 131 | ok2 = mbChol (trustSym m2) == Just (chol $ trustSym m2) |
132 | 132 | ||
133 | --------------------------------------------------------------------- | 133 | --------------------------------------------------------------------- |
134 | 134 | ||
@@ -403,8 +403,8 @@ indexProp g f x = a1 == g a2 && a2 == a3 && b1 == g b2 && b2 == b3 | |||
403 | -------------------------------------------------------------------------------- | 403 | -------------------------------------------------------------------------------- |
404 | 404 | ||
405 | sliceTest = utest "slice test" $ and | 405 | sliceTest = utest "slice test" $ and |
406 | [ testSlice chol (gen 5 :: Matrix R) | 406 | [ testSlice (chol . trustSym) (gen 5 :: Matrix R) |
407 | , testSlice chol (gen 5 :: Matrix C) | 407 | , testSlice (chol . trustSym) (gen 5 :: Matrix C) |
408 | , testSlice qr (rec :: Matrix R) | 408 | , testSlice qr (rec :: Matrix R) |
409 | , testSlice qr (rec :: Matrix C) | 409 | , testSlice qr (rec :: Matrix C) |
410 | , testSlice hess (agen 5 :: Matrix R) | 410 | , testSlice hess (agen 5 :: Matrix R) |
@@ -420,12 +420,12 @@ sliceTest = utest "slice test" $ and | |||
420 | 420 | ||
421 | , testSlice eig (agen 5 :: Matrix R) | 421 | , testSlice eig (agen 5 :: Matrix R) |
422 | , testSlice eig (agen 5 :: Matrix C) | 422 | , testSlice eig (agen 5 :: Matrix C) |
423 | , testSlice eigSH (gen 5 :: Matrix R) | 423 | , testSlice (eigSH . trustSym) (gen 5 :: Matrix R) |
424 | , testSlice eigSH (gen 5 :: Matrix C) | 424 | , testSlice (eigSH . trustSym) (gen 5 :: Matrix C) |
425 | , testSlice eigenvalues (agen 5 :: Matrix R) | 425 | , testSlice eigenvalues (agen 5 :: Matrix R) |
426 | , testSlice eigenvalues (agen 5 :: Matrix C) | 426 | , testSlice eigenvalues (agen 5 :: Matrix C) |
427 | , testSlice eigenvaluesSH (gen 5 :: Matrix R) | 427 | , testSlice (eigenvaluesSH . trustSym) (gen 5 :: Matrix R) |
428 | , testSlice eigenvaluesSH (gen 5 :: Matrix C) | 428 | , testSlice (eigenvaluesSH . trustSym) (gen 5 :: Matrix C) |
429 | 429 | ||
430 | , testSlice svd (rec :: Matrix R) | 430 | , testSlice svd (rec :: Matrix R) |
431 | , testSlice thinSVD (rec :: Matrix R) | 431 | , testSlice thinSVD (rec :: Matrix R) |
@@ -489,10 +489,10 @@ sliceTest = utest "slice test" $ and | |||
489 | , testSlice ((<>) (ogen 5:: Matrix (Z ./. 7))) (gen 5) | 489 | , testSlice ((<>) (ogen 5:: Matrix (Z ./. 7))) (gen 5) |
490 | , testSlice (flip (<>) (gen 5:: Matrix (Z ./. 7))) (ogen 5) | 490 | , testSlice (flip (<>) (gen 5:: Matrix (Z ./. 7))) (ogen 5) |
491 | 491 | ||
492 | , testSlice (flip cholSolve (agen 5:: Matrix R)) (chol $ gen 5) | 492 | , testSlice (flip cholSolve (agen 5:: Matrix R)) (chol $ trustSym $ gen 5) |
493 | , testSlice (flip cholSolve (agen 5:: Matrix C)) (chol $ gen 5) | 493 | , testSlice (flip cholSolve (agen 5:: Matrix C)) (chol $ trustSym $ gen 5) |
494 | , testSlice (cholSolve (chol $ gen 5:: Matrix R)) (agen 5) | 494 | , testSlice (cholSolve (chol $ trustSym $ gen 5:: Matrix R)) (agen 5) |
495 | , testSlice (cholSolve (chol $ gen 5:: Matrix C)) (agen 5) | 495 | , testSlice (cholSolve (chol $ trustSym $ gen 5:: Matrix C)) (agen 5) |
496 | 496 | ||
497 | , ok_qrgr (rec :: Matrix R) | 497 | , ok_qrgr (rec :: Matrix R) |
498 | , ok_qrgr (rec :: Matrix C) | 498 | , ok_qrgr (rec :: Matrix C) |
@@ -515,8 +515,8 @@ sliceTest = utest "slice test" $ and | |||
515 | 515 | ||
516 | test_lus m = testSlice f lup | 516 | test_lus m = testSlice f lup |
517 | where | 517 | where |
518 | f x = luSolve (x,p) m | 518 | f x = luSolve (LU x p) m |
519 | (lup,p) = luPacked m | 519 | (LU lup p) = luPacked m |
520 | 520 | ||
521 | gen :: Numeric t => Int -> Matrix t | 521 | gen :: Numeric t => Int -> Matrix t |
522 | gen n = diagRect 1 (konst 5 n) n n | 522 | gen n = diagRect 1 (konst 5 n) n n |
@@ -588,11 +588,11 @@ runTests n = do | |||
588 | test (linearSolveProp (luSolve.luPacked) . rSqWC) | 588 | test (linearSolveProp (luSolve.luPacked) . rSqWC) |
589 | test (linearSolveProp (luSolve.luPacked) . cSqWC) | 589 | test (linearSolveProp (luSolve.luPacked) . cSqWC) |
590 | putStrLn "------ ldlSolve" | 590 | putStrLn "------ ldlSolve" |
591 | test (linearSolveProp (ldlSolve.ldlPacked) . rSymWC) | 591 | test (linearSolvePropH (ldlSolve.ldlPacked) . rSymWC) |
592 | test (linearSolveProp (ldlSolve.ldlPacked) . cSymWC) | 592 | test (linearSolvePropH (ldlSolve.ldlPacked) . cSymWC) |
593 | putStrLn "------ cholSolve" | 593 | putStrLn "------ cholSolve" |
594 | test (linearSolveProp (cholSolve.chol) . rPosDef) | 594 | test (linearSolveProp (cholSolve.chol.trustSym) . rPosDef) |
595 | test (linearSolveProp (cholSolve.chol) . cPosDef) | 595 | test (linearSolveProp (cholSolve.chol.trustSym) . cPosDef) |
596 | putStrLn "------ luSolveLS" | 596 | putStrLn "------ luSolveLS" |
597 | test (linearSolveProp linearSolveLS . rSqWC) | 597 | test (linearSolveProp linearSolveLS . rSqWC) |
598 | test (linearSolveProp linearSolveLS . cSqWC) | 598 | test (linearSolveProp linearSolveLS . cSqWC) |
@@ -865,8 +865,8 @@ eigBench = do | |||
865 | let m = reshape 1000 (randomVector 777 Uniform (1000*1000)) | 865 | let m = reshape 1000 (randomVector 777 Uniform (1000*1000)) |
866 | s = m + tr m | 866 | s = m + tr m |
867 | m `seq` s `seq` putStrLn "" | 867 | m `seq` s `seq` putStrLn "" |
868 | time "eigenvalues symmetric 1000x1000" (eigenvaluesSH' m) | 868 | time "eigenvalues symmetric 1000x1000" (eigenvaluesSH (trustSym m)) |
869 | time "eigenvectors symmetric 1000x1000" (snd $ eigSH' m) | 869 | time "eigenvectors symmetric 1000x1000" (snd $ eigSH (trustSym m)) |
870 | time "eigenvalues general 1000x1000" (eigenvalues m) | 870 | time "eigenvalues general 1000x1000" (eigenvalues m) |
871 | time "eigenvectors general 1000x1000" (snd $ eig m) | 871 | time "eigenvectors general 1000x1000" (snd $ eig m) |
872 | 872 | ||
@@ -893,12 +893,14 @@ solveBenchN n = do | |||
893 | time ("svd solve " ++ show n) (linearSolveSVD a b) | 893 | time ("svd solve " ++ show n) (linearSolveSVD a b) |
894 | time (" ls solve " ++ show n) (linearSolveLS a b) | 894 | time (" ls solve " ++ show n) (linearSolveLS a b) |
895 | time (" solve " ++ show n) (linearSolve a b) | 895 | time (" solve " ++ show n) (linearSolve a b) |
896 | time ("cholSolve " ++ show n) (cholSolve (chol a) b) | 896 | -- time (" LU solve " ++ show n) (luSolve (luPacked a) b) |
897 | time ("LDL solve " ++ show n) (ldlSolve (ldlPacked (trustSym a)) b) | ||
898 | time ("cholSolve " ++ show n) (cholSolve (chol $ trustSym a) b) | ||
897 | 899 | ||
898 | solveBench = do | 900 | solveBench = do |
899 | solveBenchN 500 | 901 | solveBenchN 500 |
900 | solveBenchN 1000 | 902 | solveBenchN 1000 |
901 | -- solveBenchN 1500 | 903 | solveBenchN 1500 |
902 | 904 | ||
903 | -------------------------------- | 905 | -------------------------------- |
904 | 906 | ||
@@ -906,7 +908,7 @@ cholBenchN n = do | |||
906 | let x = uniformSample 777 (2*n) (replicate n (-1,1)) | 908 | let x = uniformSample 777 (2*n) (replicate n (-1,1)) |
907 | a = tr x <> x | 909 | a = tr x <> x |
908 | a `seq` putStr "" | 910 | a `seq` putStr "" |
909 | time ("chol " ++ show n) (chol a) | 911 | time ("chol " ++ show n) (chol $ trustSym a) |
910 | 912 | ||
911 | cholBench = do | 913 | cholBench = do |
912 | putStrLn "" | 914 | putStrLn "" |