summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Testing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Testing.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Testing.hs98
1 files changed, 98 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/Testing.hs b/lib/Numeric/LinearAlgebra/Testing.hs
new file mode 100644
index 0000000..dcf1d8e
--- /dev/null
+++ b/lib/Numeric/LinearAlgebra/Testing.hs
@@ -0,0 +1,98 @@
1{-# OPTIONS_GHC -XPatternSignatures #-}
2-----------------------------------------------------------------------------
3{- |
4Module : Numeric.LinearAlgebra.Testing
5Copyright : (c) Alberto Ruiz 2007
6License : GPL-style
7
8Maintainer : Alberto Ruiz (aruiz at um dot es)
9Stability : provisional
10Portability : portable
11
12Some consistency tests.
13
14-}
15
16module Numeric.LinearAlgebra.Testing(
17 runTests, runBigTests
18) where
19
20import Numeric.LinearAlgebra
21import Test.QuickCheck
22import Debug.Trace
23
24qCheck n = check defaultConfig {configSize = const n}
25
26debug x = trace (show x) x
27
28type RM = Matrix Double
29type CM = Matrix (Complex Double)
30
31instance (Arbitrary a, RealFloat a) => Arbitrary (Complex a) where
32 arbitrary = do
33 r <- arbitrary
34 i <- arbitrary
35 return (r:+i)
36 coarbitrary = undefined
37
38chooseDim = sized $ \m -> choose (1,max 1 m)
39
40instance (Field a, Arbitrary a) => Arbitrary (Vector a) where
41 arbitrary = do m <- chooseDim
42 l <- vector m
43 return $ fromList l
44 coarbitrary = undefined
45
46instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where
47 arbitrary = do
48 m <- chooseDim
49 n <- chooseDim
50 l <- vector (m*n)
51 return $ (m><n) l
52 coarbitrary = undefined
53
54
55newtype (Sq a) = Sq (Matrix a) deriving Show
56sq (Sq m) = m
57
58instance (Element a, Arbitrary a) => Arbitrary (Sq a) where
59 arbitrary = do
60 n <- chooseDim
61 l <- vector (n*n)
62 return $ Sq $ (n><n) l
63 coarbitrary = undefined
64
65newtype (Rot a) = Rot (Matrix a) deriving Show
66rot (Rot a) = a
67
68instance (Field a, Arbitrary a) => Arbitrary (Rot a) where
69 arbitrary = do
70 Sq m <- arbitrary
71 let (q,_) = qr m
72 return (Rot q)
73 coarbitrary = undefined
74
75newtype (Her a) = Her (Matrix a) deriving Show
76her (Her a) = a
77
78instance (Field a, Arbitrary a) => Arbitrary (Her a) where
79 arbitrary = do
80 Sq m <- arbitrary
81 let m' = m/2
82 return $ Her (m' + ctrans m')
83 coarbitrary = undefined
84
85-------------------------------------------------------------------
86
87herR x = her x :: RM
88
89-- | It runs all the tests.
90runTests :: Int -- ^ maximum dimension
91 -> IO ()
92runTests n = do
93 qCheck n (\(Her (m::CM))-> m == ctrans m)
94 qCheck n $ (\m->m==ctrans m) . herR
95
96-- | Some additional tests on big matrices. They take a few minutes.
97runBigTests :: IO ()
98runBigTests = undefined