packages feed

hmatrix-tests 0.6.0.0 → 0.19.0.0

raw patch · 7 files changed

+139/−14 lines, 7 filesnew-uploader

Files

hmatrix-tests.cabal view
@@ -1,5 +1,5 @@ Name:               hmatrix-tests-Version:            0.6.0.0+Version:            0.19.0.0 License:            BSD3 License-file:       LICENSE Author:             Alberto Ruiz
src/Numeric/GSL/Tests.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-incomplete-patterns #-}+{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-incomplete-patterns -fno-warn-missing-signatures #-} {- | Module      :  Numeric.GLS.Tests Copyright   :  (c) Alberto Ruiz 2014
src/Numeric/LinearAlgebra/Tests.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-incomplete-patterns #-}+{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-incomplete-patterns -fno-warn-missing-signatures #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-}@@ -31,7 +31,7 @@ --, runBigTests ) where -import Numeric.LinearAlgebra hiding (unitary)+import Numeric.LinearAlgebra import Numeric.LinearAlgebra.Devel import Numeric.LinearAlgebra.Static(L) import Numeric.LinearAlgebra.Tests.Instances@@ -39,7 +39,11 @@ import Test.HUnit hiding ((~:),test,Testable,State) import System.Info import Data.List(foldl1')+#if MIN_VERSION_base(4,11,0)+import Prelude hiding ((^),(<>))+#else import Prelude hiding ((^))+#endif import qualified Prelude import System.CPUTime import System.Exit@@ -131,6 +135,111 @@     ok1 = mbChol (trustSym m1) == Nothing     ok2 = mbChol (trustSym m2) == Just (chol $ trustSym m2) +-----------------------------------------------------++triTest = utest "triTest" ok1 where++  a :: Matrix R+  a = (4><4)+    [+       4.30,  0.00,  0.00, 0.00,+      -3.96, -4.87,  0.00, 0.00,+       0.40,  0.31, -8.02, 0.00,+      -0.27,  0.07, -5.95, 0.12+    ]++  w :: Matrix R+  w = (4><2)+    [+      -12.90, -21.50,+       16.75,  14.93,+      -17.55,   6.33,+      -11.04,   8.09+    ]++  v :: Matrix R+  v = triSolve Lower a w++  e :: Matrix R+  e = (4><2)+    [+      -3.0000, -5.0000,+      -1.0000,  1.0000,+       2.0000, -1.0000,+       1.0000,  6.0000+    ]++  ok1 = (norm_Inf . flatten $ e - v) <= 1e-13++-----------------------------------------------------++triDiagTest = utest "triDiagTest" (ok1 && ok2) where++  dL, d, dU :: Vector Double+  dL =  fromList [3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0]+  d  =  fromList [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]+  dU =  fromList [4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0]++  b :: Matrix R+  b = (9><3)+    [+      1.0,   1.0,   1.0,+      1.0,  -1.0,   2.0,+      1.0,   1.0,   3.0,+      1.0,  -1.0,   4.0,+      1.0,   1.0,   5.0,+      1.0,  -1.0,   6.0,+      1.0,   1.0,   7.0,+      1.0,  -1.0,   8.0,+      1.0,   1.0,   9.0+    ]++  y :: Matrix R+  y = (9><9)+    [+      1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,+      3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,+      0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0,+      0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0, 0.0,+      0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0, 0.0,+      0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0, 0.0,+      0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0, 0.0,+      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0, 4.0,+      0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 1.0+    ]++  x :: Matrix R+  x = triDiagSolve dL d dU b++  z :: Matrix C+  z = (4><4)+    [+      1.0 :+ 1.0, 4.0 :+ 4.0, 0.0 :+ 0.0, 0.0 :+ 0.0,+      3.0 :+ 3.0, 1.0 :+ 1.0, 4.0 :+ 4.0, 0.0 :+ 0.0,+      0.0 :+ 0.0, 3.0 :+ 3.0, 1.0 :+ 1.0, 4.0 :+ 4.0,+      0.0 :+ 0.0, 0.0 :+ 0.0, 3.0 :+ 3.0, 1.0 :+ 1.0+    ]++  zDL, zD, zDu :: Vector C+  zDL = fromList [3.0 :+ 3.0, 3.0 :+ 3.0, 3.0 :+ 3.0]+  zD  = fromList [1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ 1.0, 1.0 :+ 1.0]+  zDu = fromList [4.0 :+ 4.0, 4.0 :+ 4.0, 4.0 :+ 4.0]++  zB :: Matrix C+  zB = (4><3)+    [+      1.0 :+ 1.0,   1.0  :+   1.0,  1.0 :+ (-1.0),+      1.0 :+ 1.0, (-1.0) :+ (-1.0), 1.0 :+ (-1.0),+      1.0 :+ 1.0,   1.0  :+   1.0,  1.0 :+ (-1.0),+      1.0 :+ 1.0, (-1.0) :+ (-1.0), 1.0 :+ (-1.0)+    ]++  u :: Matrix C+  u = triDiagSolve zDL zD zDu zB++  ok1 = (maximum $ map abs $ concat $ toLists $ b - (y <> x)) <= 1e-15+  ok2 = (maximum $ map magnitude $ concat $ toLists $ zB - (z <> u)) <= 1e-15+ ---------------------------------------------------------------------  randomTestGaussian = (unSym c) :~3~: unSym (snd (meanCov dat))@@ -405,7 +514,7 @@  -------------------------------------------------------------------------------- -sliceTest = utest "slice test" $ and+_sliceTest = TestList     [ testSlice (chol . trustSym)  (gen 5 :: Matrix R)     , testSlice (chol . trustSym)  (gen 5 :: Matrix C)     , testSlice qr    (rec :: Matrix R)@@ -508,7 +617,7 @@      test_qrgr n t x = qrgr n (QR x t) -    ok_qrgr x = simeq 1E-15 q q'+    ok_qrgr x = TestCase . assertBool "ok_qrgr" $ simeq 1E-15 q q'       where         (q,_) = qr x         atau = qrRaw x@@ -537,7 +646,8 @@     rec :: Numeric t => Matrix t     rec = subMatrix (0,0) (4,5) (gen 5) -    testSlice f x@(size->sz@(r,c)) = all (==f x) (map f (g y1 ++ g y2))+    testSlice f x@(size->sz@(r,c)) =+      TestList . map (TestCase . assertEqual "" (f x)) $ (map f (g y1 ++ g y2))       where         subm = subMatrix         g y = [ subm (a*r,b*c) sz y | a <-[0..2], b <- [0..2]]@@ -715,6 +825,8 @@                        && rank ((2><3)[1,0,0,1,7*peps,0::Double]) == 2         , utest "block" $ fromBlocks [[ident 3,0],[0,ident 4]] == (ident 7 :: CM)         , mbCholTest+        , triTest+        , triDiagTest         , utest "offset" offsetTest         , normsVTest         , normsMTest@@ -730,7 +842,7 @@         , staticTest         , intTest         , modularTest-        , sliceTest+        -- , sliceTest         ]     when (errors c + failures c > 0) exitFailure     return ()
src/Numeric/LinearAlgebra/Tests/Instances.hs view
@@ -1,4 +1,8 @@-{-# LANGUAGE FlexibleContexts, UndecidableInstances, FlexibleInstances, ScopedTypeVariables #-}+{-# LANGUAGE CPP, FlexibleContexts, UndecidableInstances, FlexibleInstances, ScopedTypeVariables #-}++{-# OPTIONS_GHC -fno-warn-orphans #-}+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+ ----------------------------------------------------------------------------- {- | Module      :  Numeric.LinearAlgebra.Tests.Instances@@ -32,7 +36,9 @@ import GHC.TypeLits import Data.Proxy (Proxy(..)) import qualified Numeric.LinearAlgebra.Static as Static-+#if MIN_VERSION_base(4,11,0)+import Prelude hiding ((<>))+#endif  shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] shrinkListElementwise []     = []@@ -60,7 +66,7 @@         n :: Int         n = fromIntegral (natVal (Proxy :: Proxy n)) -    shrink v = []+    shrink _v = []  instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where     arbitrary = do@@ -87,7 +93,7 @@         n :: Int         n = fromIntegral (natVal (Proxy :: Proxy n)) -    shrink mat = []+    shrink _mat = []  -- a square matrix newtype (Sq a) = Sq (Matrix a) deriving Show
src/Numeric/LinearAlgebra/Tests/Properties.hs view
@@ -1,7 +1,10 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} +{-# OPTIONS_GHC -fno-warn-missing-signatures #-}+ ----------------------------------------------------------------------------- {- | Module      :  Numeric.LinearAlgebra.Tests.Properties@@ -50,14 +53,16 @@   , staticVectorBinaryFailProp ) where -import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary)+import Numeric.LinearAlgebra.HMatrix hiding (Testable) import qualified Numeric.LinearAlgebra.Static as Static import Test.QuickCheck  import Data.Binary import Data.Binary.Get (runGet) import Data.Either (isLeft)-import Debug.Trace (traceShowId)+#if MIN_VERSION_base(4,11,0)+import Prelude hiding ((<>))+#endif  (~=) :: Double -> Double -> Bool a ~= b = abs (a - b) < 1e-10
src/TestBase.hs view
@@ -1,3 +1,4 @@ import Numeric.LinearAlgebra.Tests +main :: IO () main = runTests 20
src/TestGSL.hs view
@@ -1,3 +1,4 @@ import Numeric.GSL.Tests +main :: IO () main = runTests 20