summaryrefslogtreecommitdiff
path: root/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs
diff options
context:
space:
mode:
authorSidharth Kapur <sidharthkapur1@gmail.com>2016-02-01 17:40:40 -0600
committerSidharth Kapur <sidharthkapur1@gmail.com>2016-02-01 17:40:40 -0600
commit8bdb87764762ef43b186bcc04caa404928df22fa (patch)
tree861ca45cf23cc3316ca3d6ada3bd0d0152fc177c /packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs
parent95c7cc6303fdb0af3ca0e1fc08cfe3ebf2674814 (diff)
some work (will probably undo this commit later)
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs')
-rw-r--r--packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs44
1 files changed, 43 insertions, 1 deletions
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs
index 046644f..0de9f37 100644
--- a/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs
+++ b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs
@@ -1,5 +1,6 @@
1{-# LANGUAGE FlexibleContexts #-} 1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE TypeFamilies #-} 2{-# LANGUAGE TypeFamilies #-}
3{-# LANGUAGE DataKinds #-}
3 4
4----------------------------------------------------------------------------- 5-----------------------------------------------------------------------------
5{- | 6{- |
@@ -39,12 +40,25 @@ module Numeric.LinearAlgebra.Tests.Properties (
39 expmDiagProp, 40 expmDiagProp,
40 multProp1, multProp2, 41 multProp1, multProp2,
41 subProp, 42 subProp,
42 linearSolveProp, linearSolvePropH, linearSolveProp2 43 linearSolveProp, linearSolvePropH, linearSolveProp2,
44
45 -- Binary properties
46 vectorBinaryRoundtripProp
47 , staticVectorBinaryRoundtripProp
48 , matrixBinaryRoundtripProp
49 , staticMatrixBinaryRoundtripProp
50 , staticVectorBinaryFailProp
43) where 51) where
44 52
45import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) 53import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary)
54import qualified Numeric.LinearAlgebra.Static as Static
46import Test.QuickCheck 55import Test.QuickCheck
47 56
57import Data.Binary
58import Data.Binary.Get (runGet)
59import Data.Either (isLeft)
60import Debug.Trace (traceShowId)
61
48(~=) :: Double -> Double -> Bool 62(~=) :: Double -> Double -> Bool
49a ~= b = abs (a - b) < 1e-10 63a ~= b = abs (a - b) < 1e-10
50 64
@@ -275,3 +289,31 @@ linearSolveProp2 f (a,x) = not wc `trivial` (not wc || a <> f a b |~| b)
275 289
276subProp m = m == (conj . tr . fromColumns . toRows) m 290subProp m = m == (conj . tr . fromColumns . toRows) m
277 291
292------------------------------------------------------------------
293
294vectorBinaryRoundtripProp :: Vector Double -> Bool
295vectorBinaryRoundtripProp vec = decode (encode vec) == vec
296
297staticVectorBinaryRoundtripProp :: Static.R 5 -> Bool
298staticVectorBinaryRoundtripProp vec =
299 let
300 decoded = decode (encode vec) :: Static.R 500
301 in
302 Static.extract decoded == Static.extract vec
303
304matrixBinaryRoundtripProp :: Matrix Double -> Bool
305matrixBinaryRoundtripProp mat = decode (encode mat) == mat
306
307staticMatrixBinaryRoundtripProp :: Static.L 100 200 -> Bool
308staticMatrixBinaryRoundtripProp mat =
309 let
310 decoded = decode (encode mat) :: Static.L 100 200
311 in
312 (Static.extract decoded) == (Static.extract mat)
313
314staticVectorBinaryFailProp :: Static.R 20 -> Bool
315staticVectorBinaryFailProp vec =
316 let
317 decoded = runGet get (encode vec) :: Either String (Static.R 50)
318 in
319 isLeft decoded