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.hs55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/Numeric/LinearAlgebra/Tests.hs b/lib/Numeric/LinearAlgebra/Tests.hs
index 77bb2f7..43a62e5 100644
--- a/lib/Numeric/LinearAlgebra/Tests.hs
+++ b/lib/Numeric/LinearAlgebra/Tests.hs
@@ -35,9 +35,12 @@ import System.CPUTime
35import Text.Printf 35import Text.Printf
36import Data.Packed.Development(unsafeFromForeignPtr,unsafeToForeignPtr) 36import Data.Packed.Development(unsafeFromForeignPtr,unsafeToForeignPtr)
37import Control.Arrow((***)) 37import Control.Arrow((***))
38import Debug.Trace
38 39
39#include "Tests/quickCheckCompat.h" 40#include "Tests/quickCheckCompat.h"
40 41
42debug x = trace (show x) x
43
41a ^ b = a Prelude.^ (b :: Int) 44a ^ b = a Prelude.^ (b :: Int)
42 45
43utest str b = TestCase $ assertBool str b 46utest str b = TestCase $ assertBool str b
@@ -217,6 +220,56 @@ offsetTest = y == y' where
217 220
218--------------------------------------------------------------------- 221---------------------------------------------------------------------
219 222
223normsVTest = TestList [
224 utest "normv2CD" $ norm2PropC v
225 , utest "normv2CF" $ norm2PropC (single v)
226 , utest "normv2D" $ norm2PropR x
227 , utest "normv2F" $ norm2PropR (single x)
228
229 , utest "normv1CD" $ norm1 v == 8
230 , utest "normv1CF" $ norm1 (single v) == 8
231 , utest "normv1D" $ norm1 x == 6
232 , utest "normv1F" $ norm1 (single x) == 6
233
234 , utest "normvInfCD" $ normInf v == 5
235 , utest "normvInfCF" $ normInf (single v) == 5
236 , utest "normvInfD" $ normInf x == 3
237 , utest "normvInfF" $ normInf (single x) == 3
238
239 ] where v = fromList [1,-2,3:+4] :: Vector (Complex Double)
240 x = fromList [1,2,-3] :: Vector Double
241 norm2PropR a = norm2 a =~= sqrt (dot a a)
242 norm2PropC a = norm2 a =~= sqrt (dot a (conj a))
243 a =~= b = fromList [a] |~| fromList [b]
244
245normsMTest = TestList [
246 utest "norm2mCD" $ pnorm PNorm2 v =~= 8.86164970498005
247 , utest "norm2mCF" $ pnorm PNorm2 (single v) =~= 8.86164970498005
248 , utest "norm2mD" $ pnorm PNorm2 x =~= 5.96667765076216
249 , utest "norm2mF" $ pnorm PNorm2 (single x) =~= 5.96667765076216
250
251 , utest "norm1mCD" $ pnorm PNorm1 v == 9
252 , utest "norm1mCF" $ pnorm PNorm1 (single v) == 9
253 , utest "norm1mD" $ pnorm PNorm1 x == 7
254 , utest "norm1mF" $ pnorm PNorm1 (single x) == 7
255
256 , utest "normmInfCD" $ pnorm Infinity v == 12
257 , utest "normmInfCF" $ pnorm Infinity (single v) == 12
258 , utest "normmInfD" $ pnorm Infinity x == 8
259 , utest "normmInfF" $ pnorm Infinity (single x) == 8
260
261 , utest "normmFroCD" $ pnorm Frobenius v =~= 8.88819441731559
262 , utest "normmFroCF" $ pnorm Frobenius (single v) =~~= 8.88819441731559
263 , utest "normmFroD" $ pnorm Frobenius x =~= 6.24499799839840
264 , utest "normmFroF" $ pnorm Frobenius (single x) =~~= 6.24499799839840
265
266 ] where v = (2><2) [1,-2*i,3:+4,7] :: Matrix (Complex Double)
267 x = (2><2) [1,2,-3,5] :: Matrix Double
268 a =~= b = fromList [a] :~10~: fromList [b]
269 a =~~= b = fromList [a] :~5~: fromList [b]
270
271---------------------------------------------------------------------
272
220 273
221-- | All tests must pass with a maximum dimension of about 20 274-- | All tests must pass with a maximum dimension of about 20
222-- (some tests may fail with bigger sizes due to precision loss). 275-- (some tests may fail with bigger sizes due to precision loss).
@@ -373,6 +426,8 @@ runTests n = do
373 , fittingTest 426 , fittingTest
374 , mbCholTest 427 , mbCholTest
375 , utest "offset" offsetTest 428 , utest "offset" offsetTest
429 , normsVTest
430 , normsMTest
376 ] 431 ]
377 return () 432 return ()
378 433