summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/experiments/bigtests.hs (renamed from examples/tests.hs)40
1 files changed, 31 insertions, 9 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