diff options
Diffstat (limited to 'packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs')
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs | 44 |
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 | ||
45 | import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) | 53 | import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) |
54 | import qualified Numeric.LinearAlgebra.Static as Static | ||
46 | import Test.QuickCheck | 55 | import Test.QuickCheck |
47 | 56 | ||
57 | import Data.Binary | ||
58 | import Data.Binary.Get (runGet) | ||
59 | import Data.Either (isLeft) | ||
60 | import Debug.Trace (traceShowId) | ||
61 | |||
48 | (~=) :: Double -> Double -> Bool | 62 | (~=) :: Double -> Double -> Bool |
49 | a ~= b = abs (a - b) < 1e-10 | 63 | a ~= 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 | ||
276 | subProp m = m == (conj . tr . fromColumns . toRows) m | 290 | subProp m = m == (conj . tr . fromColumns . toRows) m |
277 | 291 | ||
292 | ------------------------------------------------------------------ | ||
293 | |||
294 | vectorBinaryRoundtripProp :: Vector Double -> Bool | ||
295 | vectorBinaryRoundtripProp vec = decode (encode vec) == vec | ||
296 | |||
297 | staticVectorBinaryRoundtripProp :: Static.R 5 -> Bool | ||
298 | staticVectorBinaryRoundtripProp vec = | ||
299 | let | ||
300 | decoded = decode (encode vec) :: Static.R 500 | ||
301 | in | ||
302 | Static.extract decoded == Static.extract vec | ||
303 | |||
304 | matrixBinaryRoundtripProp :: Matrix Double -> Bool | ||
305 | matrixBinaryRoundtripProp mat = decode (encode mat) == mat | ||
306 | |||
307 | staticMatrixBinaryRoundtripProp :: Static.L 100 200 -> Bool | ||
308 | staticMatrixBinaryRoundtripProp mat = | ||
309 | let | ||
310 | decoded = decode (encode mat) :: Static.L 100 200 | ||
311 | in | ||
312 | (Static.extract decoded) == (Static.extract mat) | ||
313 | |||
314 | staticVectorBinaryFailProp :: Static.R 20 -> Bool | ||
315 | staticVectorBinaryFailProp vec = | ||
316 | let | ||
317 | decoded = runGet get (encode vec) :: Either String (Static.R 50) | ||
318 | in | ||
319 | isLeft decoded | ||