summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/tests.hs38
1 files changed, 36 insertions, 2 deletions
diff --git a/examples/tests.hs b/examples/tests.hs
index 50f0a03..047794c 100644
--- a/examples/tests.hs
+++ b/examples/tests.hs
@@ -206,29 +206,63 @@ singular fun m = s1 < prec || s2/s1 < prec
206 s1 = maximum s 206 s1 = maximum s
207 s2 = minimum s 207 s2 = minimum s
208 208
209{-
210invTest msg m = do
211 assertBool msg $ m <> inv m =~= ident (rows m)
212
213invComplexTest msg m = do
214 assertBool msg $ m <> invC m =~= identC (rows m)
215
216invC m = linearSolveC m (identC (rows m))
217
218identC n = toComplex(ident n, (0::Double) <>ident n)
219-}
220
221--------------------------------------------------------------------
222
223pinvTest f feq m = (m <> f m <> m) `feq` m
224 where (<>) = mulF
225
226pinvR m = linearSolveLSR m (ident (rows m))
227pinvC m = linearSolveLSC m (ident (rows m))
228
229pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m))
230
231pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m))
232
209main = do 233main = do
234 putStrLn "--------- general -----"
235 quickCheck (\(Sym m) -> m |=| (trans m:: Matrix BaseType))
210 quickCheck $ \l -> null l || (toList . fromList) l == (l :: [BaseType]) 236 quickCheck $ \l -> null l || (toList . fromList) l == (l :: [BaseType])
237
211 quickCheck $ \m -> m |=| asC (m :: Matrix BaseType) 238 quickCheck $ \m -> m |=| asC (m :: Matrix BaseType)
212 quickCheck $ \m -> m |=| asFortran (m :: Matrix BaseType) 239 quickCheck $ \m -> m |=| asFortran (m :: Matrix BaseType)
213 quickCheck $ \m -> m |=| (asC . asFortran) (m :: Matrix BaseType) 240 quickCheck $ \m -> m |=| (asC . asFortran) (m :: Matrix BaseType)
241 putStrLn "--------- MULTIPLY ----"
214 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| mulF m1 (m2 :: Matrix BaseType) 242 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| mulF m1 (m2 :: Matrix BaseType)
215 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| trans (mulF (trans m2) (trans m1 :: Matrix BaseType)) 243 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| trans (mulF (trans m2) (trans m1 :: Matrix BaseType))
216 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| multiplyG m1 (m2 :: Matrix BaseType) 244 quickCheck $ \(PairM m1 m2) -> mulC m1 m2 |=| multiplyG m1 (m2 :: Matrix BaseType)
245 putStrLn "--------- SVD ---------"
217 quickCheck (svdTestR mulC) 246 quickCheck (svdTestR mulC)
218 quickCheck (svdTestR mulF) 247 quickCheck (svdTestR mulF)
219 quickCheck (svdTestC mulC) 248 quickCheck (svdTestC mulC)
220 quickCheck (svdTestC mulF) 249 quickCheck (svdTestC mulF)
250 putStrLn "--------- EIG ---------"
221 quickCheck (eigTestC mulC) 251 quickCheck (eigTestC mulC)
222 quickCheck (eigTestC mulF) 252 quickCheck (eigTestC mulF)
223 quickCheck (eigTestR mulC) 253 quickCheck (eigTestR mulC)
224 quickCheck (eigTestR mulF) 254 quickCheck (eigTestR mulF)
225 quickCheck (\(Sym m) -> m |=| (trans m:: Matrix BaseType))
226 quickCheck (eigTestS mulC) 255 quickCheck (eigTestS mulC)
227 quickCheck (eigTestS mulF) 256 quickCheck (eigTestS mulF)
228 quickCheck (eigTestH mulC) 257 quickCheck (eigTestH mulC)
229 quickCheck (eigTestH mulF) 258 quickCheck (eigTestH mulF)
259 putStrLn "--------- SOLVE ---------"
230 quickCheck (linearSolveSQTest linearSolveR (|~|) (singular svdR') mulC) 260 quickCheck (linearSolveSQTest linearSolveR (|~|) (singular svdR') mulC)
231 quickCheck (linearSolveSQTest linearSolveC (|~~|) (singular svdC') mulC) 261 quickCheck (linearSolveSQTest linearSolveC (|~~|) (singular svdC') mulF)
262 quickCheck (pinvTest pinvR (|~|))
263 quickCheck (pinvTest pinvC (|~~|))
264 quickCheck (pinvTest pinvSVDR (|~|))
265 quickCheck (pinvTest pinvSVDC (|~~|))
232 266
233kk = (2><2) 267kk = (2><2)
234 [ 1.0, 0.0 268 [ 1.0, 0.0