diff options
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 | ||
12 | pseudorandomC seed (n,m) = toComplex (pseudorandomR seed (n,m), pseudorandomR (seed+1) (n,m)) | 12 | pseudorandomC seed (n,m) = toComplex (pseudorandomR seed (n,m), pseudorandomR (seed+1) (n,m)) |
13 | 13 | ||
14 | bigmat = m + trans m :: RM | 14 | bigmat = m + trans m |
15 | where m = pseudorandomR 18 (1000,1000) | 15 | where m = pseudorandomR 18 (1000,1000) :: Matrix Double |
16 | bigmatc = mc + ctrans mc ::CM | 16 | bigmatc = mc + ctrans mc |
17 | where mc = pseudorandomC 19 (1000,1000) | 17 | where mc = pseudorandomC 19 (1000,1000) :: Matrix (Complex Double) |
18 | 18 | ||
19 | utest str b = TestCase $ assertBool str b | 19 | utest str b = TestCase $ assertBool str b |
20 | 20 | ||
21 | feye n = flipud (ident n) :: Matrix Double | 21 | feye n = flipud (ident n) :: Matrix Double |
22 | 22 | ||
23 | infixl 4 |~| | ||
24 | a |~| b = dist a b < 10^^(-10) | ||
25 | |||
26 | dist 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 | |||
37 | square m = rows m == cols m | ||
38 | |||
39 | unitary m = square m && m <> ctrans m |~| ident (rows m) | ||
40 | |||
41 | eigProp m = complex m <> v |~| v <> diag s | ||
42 | where (s, v) = eig m | ||
43 | |||
44 | eigSHProp 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 | |||
23 | bigtests = do | 49 | bigtests = 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 | ||
34 | main = do | 60 | main = bigtests |
35 | args <- getArgs | ||
36 | if "--big" `elem` args | ||
37 | then bigtests | ||
38 | else runTests 20 | ||