summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Tests/Instances.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests/Instances.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Tests/Instances.hs63
1 files changed, 58 insertions, 5 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests/Instances.hs b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
index 583143a..af486c8 100644
--- a/lib/Numeric/LinearAlgebra/Tests/Instances.hs
+++ b/lib/Numeric/LinearAlgebra/Tests/Instances.hs
@@ -14,10 +14,13 @@ Arbitrary instances for vectors, matrices.
14-} 14-}
15 15
16module Numeric.LinearAlgebra.Tests.Instances( 16module Numeric.LinearAlgebra.Tests.Instances(
17 Sq(..), 17 Sq(..), rSq,cSq,
18 Rot(..), 18 Rot(..), rRot,cRot,
19 Her(..), 19 Her(..), rHer,cHer,
20 WC(..) 20 WC(..), rWC,cWC,
21 SqWC(..), rSqWC, cSqWC,
22 PosDef(..), rPosDef, cPosDef,
23 RM,CM, rM,cM
21) where 24) where
22 25
23import Numeric.LinearAlgebra 26import Numeric.LinearAlgebra
@@ -74,7 +77,7 @@ instance (Field a, Arbitrary a) => Arbitrary (Her a) where
74 return $ Her (m' + ctrans m') 77 return $ Her (m' + ctrans m')
75 coarbitrary = undefined 78 coarbitrary = undefined
76 79
77-- a well-conditioned matrix (the singular values are between 1 and 100) 80-- a well-conditioned general matrix (the singular values are between 1 and 100)
78newtype (WC a) = WC (Matrix a) deriving Show 81newtype (WC a) = WC (Matrix a) deriving Show
79instance (Field a, Arbitrary a) => Arbitrary (WC a) where 82instance (Field a, Arbitrary a) => Arbitrary (WC a) where
80 arbitrary = do 83 arbitrary = do
@@ -87,3 +90,53 @@ instance (Field a, Arbitrary a) => Arbitrary (WC a) where
87 let s = diagRect (fromList sv) r c 90 let s = diagRect (fromList sv) r c
88 return $ WC (u <> real s <> trans v) 91 return $ WC (u <> real s <> trans v)
89 coarbitrary = undefined 92 coarbitrary = undefined
93
94-- a well-conditioned square matrix (the singular values are between 1 and 100)
95newtype (SqWC a) = SqWC (Matrix a) deriving Show
96instance (Field a, Arbitrary a) => Arbitrary (SqWC a) where
97 arbitrary = do
98 Sq m <- arbitrary
99 let (u,_,v) = svd m
100 n = rows m
101 sv <- replicateM n (choose (1,100))
102 let s = diag (fromList sv)
103 return $ SqWC (u <> real s <> trans v)
104 coarbitrary = undefined
105
106-- a positive definite square matrix (the eigenvalues are between 0 and 100)
107newtype (PosDef a) = PosDef (Matrix a) deriving Show
108instance (Field a, Arbitrary a) => Arbitrary (PosDef a) where
109 arbitrary = do
110 Her m <- arbitrary
111 let (_,v) = eigSH m
112 n = rows m
113 l <- replicateM n (choose (0,100))
114 let s = diag (fromList l)
115 p = v <> real s <> ctrans v
116 return $ PosDef (0.5 .* p + 0.5 .* ctrans p)
117 coarbitrary = undefined
118
119type RM = Matrix Double
120type CM = Matrix (Complex Double)
121
122rM m = m :: RM
123cM m = m :: CM
124
125rHer (Her m) = m :: RM
126cHer (Her m) = m :: CM
127
128rRot (Rot m) = m :: RM
129cRot (Rot m) = m :: CM
130
131rSq (Sq m) = m :: RM
132cSq (Sq m) = m :: CM
133
134rWC (WC m) = m :: RM
135cWC (WC m) = m :: CM
136
137rSqWC (SqWC m) = m :: RM
138cSqWC (SqWC m) = m :: CM
139
140rPosDef (PosDef m) = m :: RM
141cPosDef (PosDef m) = m :: CM
142