summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-09 16:29:46 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-09 16:29:46 +0000
commitf2cf177e93d4578b404909c68b24625a76466ee5 (patch)
tree28dabd5ae200ad1fbfdf41333599bb6ecccc571f /examples
parent7931a9b18ea84ed5f49e2803ba596f190567d9d8 (diff)
eigC
Diffstat (limited to 'examples')
-rw-r--r--examples/tests.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/tests.hs b/examples/tests.hs
index f167b92..5af33ba 100644
--- a/examples/tests.hs
+++ b/examples/tests.hs
@@ -66,6 +66,8 @@ aproxL fun v1 v2 = sum (zipWith (\a b-> fun (a-b)) v1 v2) / fromIntegral (length
66(|~|) = aprox abs 66(|~|) = aprox abs
67(|~~|) = aprox magnitude 67(|~~|) = aprox magnitude
68 68
69v1 ~~ v2 = reshape 1 v1 |~~| reshape 1 v2
70
69eps = 1E-8::Double 71eps = 1E-8::Double
70 72
71asFortran m = (rows m >|< cols m) $ toList (fdat m) 73asFortran m = (rows m >|< cols m) $ toList (fdat m)
@@ -116,6 +118,15 @@ instance (Num a, Field a, Arbitrary a) => Arbitrary (PairM a) where
116 --return $ PairM ((a><b) l1) ((b><c) l2) 118 --return $ PairM ((a><b) l1) ((b><c) l2)
117 coarbitrary = undefined 119 coarbitrary = undefined
118 120
121data SqM a = SqM (Matrix a) deriving Show
122instance (Field a, Arbitrary a) => Arbitrary (SqM a) where
123 arbitrary = do
124 n <- choose (1,10)
125 l <- vector (n*n)
126 return $ SqM $ (n><n) l
127 coarbitrary = undefined
128
129
119type BaseType = Double 130type BaseType = Double
120 131
121 132
@@ -133,6 +144,14 @@ svdTestC fun prod m = u <> s' <> (trans v) |~~| m
133 (<>) = prod 144 (<>) = prod
134 s' = liftMatrix comp s 145 s' = liftMatrix comp s
135 146
147eigTestC fun prod (SqM m) = (m <> v) |~~| (v <> diag s)
148 && takeDiag ((liftMatrix conj (trans v)) `mulC` v) ~~ constant (rows m) 1
149 where (s,v) = fun m
150 (<>) = prod
151
152takeDiag m = fromList [cdat m `at` (k*cols m+k) | k <- [0 .. min (rows m) (cols m) -1]]
153
154
136comp v = toComplex (v,constant (dim v) 0) 155comp v = toComplex (v,constant (dim v) 0)
137 156
138main = do 157main = do
@@ -147,3 +166,4 @@ main = do
147 quickCheck (svdTestR svdR mulF) 166 quickCheck (svdTestR svdR mulF)
148 quickCheck (svdTestC svdC mulC) 167 quickCheck (svdTestC svdC mulC)
149 quickCheck (svdTestC svdC mulF) 168 quickCheck (svdTestC svdC mulF)
169 quickCheck (eigTestC eigC mulC)