summaryrefslogtreecommitdiff
path: root/lib/Numeric/LinearAlgebra/Tests.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/LinearAlgebra/Tests.hs')
-rw-r--r--lib/Numeric/LinearAlgebra/Tests.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 5c5135c..e3b6e1f 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -45,6 +45,8 @@ a ~~ b = fromList a |~| fromList b
45 45
46feye n = flipud (ident n) :: Matrix Double 46feye n = flipud (ident n) :: Matrix Double
47 47
48-----------------------------------------------------------
49
48detTest1 = det m == 26 50detTest1 = det m == 26
49 && det mc == 38 :+ (-3) 51 && det mc == 38 :+ (-3)
50 && det (feye 2) == -1 52 && det (feye 2) == -1
@@ -314,17 +316,27 @@ runTests n = do
314 test (expmDiagProp . cSqWC) 316 test (expmDiagProp . cSqWC)
315 putStrLn "------ fft" 317 putStrLn "------ fft"
316 test (\v -> ifft (fft v) |~| v) 318 test (\v -> ifft (fft v) |~| v)
317 putStrLn "------ vector operations" 319 putStrLn "------ vector operations - Double"
318 test (\u -> sin u ^ 2 + cos u ^ 2 |~| (1::RM)) 320 test (\u -> sin u ^ 2 + cos u ^ 2 |~| (1::RM))
319 test $ (\u -> sin u ^ 2 + cos u ^ 2 |~| (1::CM)) . liftMatrix makeUnitary 321 test $ (\u -> sin u ^ 2 + cos u ^ 2 |~| (1::CM)) . liftMatrix makeUnitary
320 test (\u -> sin u ** 2 + cos u ** 2 |~| (1::RM)) 322 test (\u -> sin u ** 2 + cos u ** 2 |~| (1::RM))
321 test (\u -> cos u * tan u |~| sin (u::RM)) 323 test (\u -> cos u * tan u |~| sin (u::RM))
322 test $ (\u -> cos u * tan u |~| sin (u::CM)) . liftMatrix makeUnitary 324 test $ (\u -> cos u * tan u |~| sin (u::CM)) . liftMatrix makeUnitary
325 putStrLn "------ vector operations - Float"
326 test (\u -> sin u ^ 2 + cos u ^ 2 |~~| (1::FM))
327 test $ (\u -> sin u ^ 2 + cos u ^ 2 |~~| (1::ZM)) . liftMatrix makeUnitary
328 test (\u -> sin u ** 2 + cos u ** 2 |~~| (1::FM))
329 test (\u -> cos u * tan u |~~| sin (u::FM))
330 test $ (\u -> cos u * tan u |~~| sin (u::ZM)) . liftMatrix makeUnitary
323 putStrLn "------ read . show" 331 putStrLn "------ read . show"
324 test (\m -> (m::RM) == read (show m)) 332 test (\m -> (m::RM) == read (show m))
325 test (\m -> (m::CM) == read (show m)) 333 test (\m -> (m::CM) == read (show m))
326 test (\m -> toRows (m::RM) == read (show (toRows m))) 334 test (\m -> toRows (m::RM) == read (show (toRows m)))
327 test (\m -> toRows (m::CM) == read (show (toRows m))) 335 test (\m -> toRows (m::CM) == read (show (toRows m)))
336 test (\m -> (m::FM) == read (show m))
337 test (\m -> (m::ZM) == read (show m))
338 test (\m -> toRows (m::FM) == read (show (toRows m)))
339 test (\m -> toRows (m::ZM) == read (show (toRows m)))
328 putStrLn "------ some unit tests" 340 putStrLn "------ some unit tests"
329 _ <- runTestTT $ TestList 341 _ <- runTestTT $ TestList
330 [ utest "1E5 rots" rotTest 342 [ utest "1E5 rots" rotTest
@@ -358,6 +370,11 @@ runTests n = do
358 ] 370 ]
359 return () 371 return ()
360 372
373
374-- single precision approximate equality
375infixl 4 |~~|
376a |~~| b = a :~6~: b
377
361makeUnitary v | realPart n > 1 = v / scalar n 378makeUnitary v | realPart n > 1 = v / scalar n
362 | otherwise = v 379 | otherwise = v
363 where n = sqrt (conj v <.> v) 380 where n = sqrt (conj v <.> v)