summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/experiments/bigtests.hs (renamed from examples/tests.hs)40
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs7
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Properties.hs2
3 files changed, 36 insertions, 13 deletions
diff --git a/examples/tests.hs b/examples/experiments/bigtests.hs
index cd923cd..a3dfad2 100644
--- a/examples/tests.hs
+++ b/examples/experiments/bigtests.hs
@@ -11,15 +11,41 @@ pseudorandomR seed (n,m) = reshape m $ fromList $ take (n*m) $ randomRs (-100,10
11 11
12pseudorandomC seed (n,m) = toComplex (pseudorandomR seed (n,m), pseudorandomR (seed+1) (n,m)) 12pseudorandomC seed (n,m) = toComplex (pseudorandomR seed (n,m), pseudorandomR (seed+1) (n,m))
13 13
14bigmat = m + trans m :: RM 14bigmat = m + trans m
15 where m = pseudorandomR 18 (1000,1000) 15 where m = pseudorandomR 18 (1000,1000) :: Matrix Double
16bigmatc = mc + ctrans mc ::CM 16bigmatc = mc + ctrans mc
17 where mc = pseudorandomC 19 (1000,1000) 17 where mc = pseudorandomC 19 (1000,1000) :: Matrix (Complex Double)
18 18
19utest str b = TestCase $ assertBool str b 19utest str b = TestCase $ assertBool str b
20 20
21feye n = flipud (ident n) :: Matrix Double 21feye n = flipud (ident n) :: Matrix Double
22 22
23infixl 4 |~|
24a |~| b = dist a b < 10^^(-10)
25
26dist a b = r
27 where norm = pnorm Infinity
28 na = norm a
29 nb = norm b
30 nab = norm (a-b)
31 mx = max na nb
32 mn = min na nb
33 r = if mn < eps
34 then mx
35 else nab/mx
36
37square m = rows m == cols m
38
39unitary m = square m && m <> ctrans m |~| ident (rows m)
40
41eigProp m = complex m <> v |~| v <> diag s
42 where (s, v) = eig m
43
44eigSHProp m = m <> v |~| v <> real (diag s)
45 && unitary v
46 && m |~| v <> real (diag s) <> ctrans v
47 where (s, v) = eigSH m
48
23bigtests = do 49bigtests = do
24 putStrLn "--------- big matrices -----" 50 putStrLn "--------- big matrices -----"
25 runTestTT $ TestList 51 runTestTT $ TestList
@@ -31,8 +57,4 @@ bigtests = do
31 ] 57 ]
32 return () 58 return ()
33 59
34main = do 60main = bigtests
35 args <- getArgs
36 if "--big" `elem` args
37 then bigtests
38 else runTests 20
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 96280fb..31ba2ff 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -13,8 +13,8 @@ Some tests.
13-} 13-}
14 14
15module Numeric.LinearAlgebra.Tests( 15module Numeric.LinearAlgebra.Tests(
16 module Numeric.LinearAlgebra.Tests.Instances, 16-- module Numeric.LinearAlgebra.Tests.Instances,
17 module Numeric.LinearAlgebra.Tests.Properties, 17-- module Numeric.LinearAlgebra.Tests.Properties,
18 qCheck, runTests 18 qCheck, runTests
19--, runBigTests 19--, runBigTests
20) where 20) where
@@ -116,7 +116,8 @@ rotTest = fun (10^5) :~12~: rot 5E4
116 where angles = toList $ linspace n (0,1) 116 where angles = toList $ linspace n (0,1)
117 117
118 118
119-- | It runs all the tests. 119-- | All tests must pass with a maximum dimension of about 20
120-- (some tests may fail with bigger sizes due to precision loss).
120runTests :: Int -- ^ maximum dimension 121runTests :: Int -- ^ maximum dimension
121 -> IO () 122 -> IO ()
122runTests n = do 123runTests n = do
diff --git a/lib/Numeric/LinearAlgebra/Tests/Properties.hs b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
index 0563e62..566d038 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Properties.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Properties.hs
@@ -144,6 +144,6 @@ cholProp m = m |~| ctrans c <> c && upperTriang c
144 where c = chol m 144 where c = chol m
145 pos = positiveDefinite m 145 pos = positiveDefinite m
146 146
147expmDiagProp m = expm (logm m) |~| complex m 147expmDiagProp m = expm (logm m) :~ 7 ~: complex m
148 where logm m = matFunc log m 148 where logm m = matFunc log m
149 149