diff options
author | Sidharth Kapur <sidharthkapur1@gmail.com> | 2016-02-01 17:40:40 -0600 |
---|---|---|
committer | Sidharth Kapur <sidharthkapur1@gmail.com> | 2016-02-01 17:40:40 -0600 |
commit | 8bdb87764762ef43b186bcc04caa404928df22fa (patch) | |
tree | 861ca45cf23cc3316ca3d6ada3bd0d0152fc177c /packages | |
parent | 95c7cc6303fdb0af3ca0e1fc08cfe3ebf2674814 (diff) |
some work (will probably undo this commit later)
Diffstat (limited to 'packages')
37 files changed, 151 insertions, 19 deletions
diff --git a/packages/base/hmatrix.cabal b/packages/base/hmatrix.cabal index 9fa3c4e..5524d2b 100644 --- a/packages/base/hmatrix.cabal +++ b/packages/base/hmatrix.cabal | |||
@@ -79,8 +79,7 @@ library | |||
79 | src/Internal/C/vector-aux.c | 79 | src/Internal/C/vector-aux.c |
80 | 80 | ||
81 | 81 | ||
82 | extensions: ForeignFunctionInterface, | 82 | extensions: ForeignFunctionInterface |
83 | CPP | ||
84 | 83 | ||
85 | ghc-options: -Wall | 84 | ghc-options: -Wall |
86 | -fno-warn-missing-signatures | 85 | -fno-warn-missing-signatures |
diff --git a/packages/base/src/Internal/Matrix.hs b/packages/base/src/Internal/Matrix.hs index 3082e8d..f9b02ca 100644 --- a/packages/base/src/Internal/Matrix.hs +++ b/packages/base/src/Internal/Matrix.hs | |||
@@ -5,6 +5,7 @@ | |||
5 | {-# LANGUAGE TypeOperators #-} | 5 | {-# LANGUAGE TypeOperators #-} |
6 | {-# LANGUAGE TypeFamilies #-} | 6 | {-# LANGUAGE TypeFamilies #-} |
7 | {-# LANGUAGE ViewPatterns #-} | 7 | {-# LANGUAGE ViewPatterns #-} |
8 | {-# LANGUAGE DeriveGeneric #-} | ||
8 | 9 | ||
9 | 10 | ||
10 | 11 | ||
diff --git a/packages/base/src/Internal/Static.hs b/packages/base/src/Internal/Static.hs index 419ff07..0ad2cad 100644 --- a/packages/base/src/Internal/Static.hs +++ b/packages/base/src/Internal/Static.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | #if __GLASGOW_HASKELL__ >= 708 | 2 | #if __GLASGOW_HASKELL__ >= 708 |
2 | 3 | ||
3 | {-# LANGUAGE DataKinds #-} | 4 | {-# LANGUAGE DataKinds #-} |
@@ -12,6 +13,7 @@ | |||
12 | {-# LANGUAGE TypeOperators #-} | 13 | {-# LANGUAGE TypeOperators #-} |
13 | {-# LANGUAGE ViewPatterns #-} | 14 | {-# LANGUAGE ViewPatterns #-} |
14 | {-# LANGUAGE BangPatterns #-} | 15 | {-# LANGUAGE BangPatterns #-} |
16 | {-# LANGUAGE DeriveGeneric #-} | ||
15 | 17 | ||
16 | {- | | 18 | {- | |
17 | Module : Internal.Static | 19 | Module : Internal.Static |
@@ -33,6 +35,8 @@ import Control.DeepSeq | |||
33 | import Data.Proxy(Proxy) | 35 | import Data.Proxy(Proxy) |
34 | import Foreign.Storable(Storable) | 36 | import Foreign.Storable(Storable) |
35 | import Text.Printf | 37 | import Text.Printf |
38 | import Data.Binary | ||
39 | import GHC.Generics (Generic) | ||
36 | 40 | ||
37 | -------------------------------------------------------------------------------- | 41 | -------------------------------------------------------------------------------- |
38 | 42 | ||
@@ -40,7 +44,14 @@ type ℝ = Double | |||
40 | type ℂ = Complex Double | 44 | type ℂ = Complex Double |
41 | 45 | ||
42 | newtype Dim (n :: Nat) t = Dim t | 46 | newtype Dim (n :: Nat) t = Dim t |
43 | deriving Show | 47 | deriving (Show, Generic) |
48 | |||
49 | instance Binary a => Binary (Complex a) | ||
50 | where | ||
51 | put (r :+ i) = put (r, i) | ||
52 | get = (\(r,i) -> r :+ i) <$> get | ||
53 | |||
54 | instance (Binary a) => Binary (Dim n a) | ||
44 | 55 | ||
45 | lift1F | 56 | lift1F |
46 | :: (c t -> c t) | 57 | :: (c t -> c t) |
@@ -58,15 +69,21 @@ instance NFData t => NFData (Dim n t) where | |||
58 | -------------------------------------------------------------------------------- | 69 | -------------------------------------------------------------------------------- |
59 | 70 | ||
60 | newtype R n = R (Dim n (Vector ℝ)) | 71 | newtype R n = R (Dim n (Vector ℝ)) |
61 | deriving (Num,Fractional,Floating) | 72 | deriving (Num,Fractional,Floating,Generic) |
62 | 73 | ||
63 | newtype C n = C (Dim n (Vector ℂ)) | 74 | newtype C n = C (Dim n (Vector ℂ)) |
64 | deriving (Num,Fractional,Floating) | 75 | deriving (Num,Fractional,Floating,Generic) |
65 | 76 | ||
66 | newtype L m n = L (Dim m (Dim n (Matrix ℝ))) | 77 | newtype L m n = L (Dim m (Dim n (Matrix ℝ))) |
78 | deriving (Generic) | ||
67 | 79 | ||
68 | newtype M m n = M (Dim m (Dim n (Matrix ℂ))) | 80 | newtype M m n = M (Dim m (Dim n (Matrix ℂ))) |
81 | deriving (Generic) | ||
69 | 82 | ||
83 | instance (KnownNat n) => Binary (R n) | ||
84 | instance (KnownNat n) => Binary (C n) | ||
85 | instance (KnownNat m, KnownNat n) => Binary (L m n) | ||
86 | instance (KnownNat m, KnownNat n) => Binary (M m n) | ||
70 | 87 | ||
71 | mkR :: Vector ℝ -> R n | 88 | mkR :: Vector ℝ -> R n |
72 | mkR = R . Dim | 89 | mkR = R . Dim |
diff --git a/packages/gsl/hmatrix-gsl.cabal b/packages/gsl/hmatrix-gsl.cabal index d009994..bfd1abf 100644 --- a/packages/gsl/hmatrix-gsl.cabal +++ b/packages/gsl/hmatrix-gsl.cabal | |||
@@ -29,8 +29,7 @@ library | |||
29 | process, random | 29 | process, random |
30 | 30 | ||
31 | 31 | ||
32 | Extensions: ForeignFunctionInterface, | 32 | Extensions: ForeignFunctionInterface |
33 | CPP | ||
34 | 33 | ||
35 | hs-source-dirs: src | 34 | hs-source-dirs: src |
36 | Exposed-modules: Numeric.GSL.Differentiation, | 35 | Exposed-modules: Numeric.GSL.Differentiation, |
diff --git a/packages/gsl/src/Numeric/GSL/Polynomials.hs b/packages/gsl/src/Numeric/GSL/Polynomials.hs index 8890f8f..46a31f3 100644 --- a/packages/gsl/src/Numeric/GSL/Polynomials.hs +++ b/packages/gsl/src/Numeric/GSL/Polynomials.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | {- | | 2 | {- | |
2 | Module : Numeric.GSL.Polynomials | 3 | Module : Numeric.GSL.Polynomials |
3 | Copyright : (c) Alberto Ruiz 2006 | 4 | Copyright : (c) Alberto Ruiz 2006 |
@@ -24,7 +25,7 @@ import System.IO.Unsafe (unsafePerformIO) | |||
24 | import Foreign.C.Types (CInt(..)) | 25 | import Foreign.C.Types (CInt(..)) |
25 | #endif | 26 | #endif |
26 | 27 | ||
27 | {- | Solution of general polynomial equations, using /gsl_poly_complex_solve/. | 28 | {- | Solution of general polynomial equations, using /gsl_poly_complex_solve/. |
28 | 29 | ||
29 | For example, the three solutions of x^3 + 8 = 0 | 30 | For example, the three solutions of x^3 + 8 = 0 |
30 | 31 | ||
@@ -41,7 +42,7 @@ The example in the GSL manual: To find the roots of x^5 -1 = 0: | |||
41 | 0.30901699437494756 :+ (-0.9510565162951535), | 42 | 0.30901699437494756 :+ (-0.9510565162951535), |
42 | 1.0000000000000002 :+ 0.0] | 43 | 1.0000000000000002 :+ 0.0] |
43 | 44 | ||
44 | -} | 45 | -} |
45 | polySolve :: [Double] -> [Complex Double] | 46 | polySolve :: [Double] -> [Complex Double] |
46 | polySolve = toList . polySolve' . fromList | 47 | polySolve = toList . polySolve' . fromList |
47 | 48 | ||
diff --git a/packages/special/hmatrix-special.cabal b/packages/special/hmatrix-special.cabal index 3b122c8..368ed2c 100644 --- a/packages/special/hmatrix-special.cabal +++ b/packages/special/hmatrix-special.cabal | |||
@@ -29,8 +29,7 @@ flag safe-cheap | |||
29 | library | 29 | library |
30 | Build-Depends: base <5, hmatrix>=0.17, hmatrix-gsl | 30 | Build-Depends: base <5, hmatrix>=0.17, hmatrix-gsl |
31 | 31 | ||
32 | Extensions: ForeignFunctionInterface, | 32 | Extensions: ForeignFunctionInterface |
33 | CPP | ||
34 | 33 | ||
35 | hs-source-dirs: lib | 34 | hs-source-dirs: lib |
36 | 35 | ||
@@ -67,7 +66,7 @@ library | |||
67 | other-modules: Numeric.GSL.Special.Internal | 66 | other-modules: Numeric.GSL.Special.Internal |
68 | 67 | ||
69 | ghc-options: -Wall -fno-warn-unused-binds | 68 | ghc-options: -Wall -fno-warn-unused-binds |
70 | 69 | ||
71 | if flag(safe-cheap) | 70 | if flag(safe-cheap) |
72 | cpp-options: -DSAFE_CHEAP=safe | 71 | cpp-options: -DSAFE_CHEAP=safe |
73 | else | 72 | else |
diff --git a/packages/special/lib/Numeric/GSL/Special/Airy.hs b/packages/special/lib/Numeric/GSL/Special/Airy.hs index 737de7c..78f14b8 100644 --- a/packages/special/lib/Numeric/GSL/Special/Airy.hs +++ b/packages/special/lib/Numeric/GSL/Special/Airy.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Airy | 4 | -- Module : Numeric.GSL.Special.Airy |
diff --git a/packages/special/lib/Numeric/GSL/Special/Bessel.hs b/packages/special/lib/Numeric/GSL/Special/Bessel.hs index 4a80c28..70066f8 100644 --- a/packages/special/lib/Numeric/GSL/Special/Bessel.hs +++ b/packages/special/lib/Numeric/GSL/Special/Bessel.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Bessel | 4 | -- Module : Numeric.GSL.Special.Bessel |
diff --git a/packages/special/lib/Numeric/GSL/Special/Clausen.hs b/packages/special/lib/Numeric/GSL/Special/Clausen.hs index 80bd45c..c495c99 100644 --- a/packages/special/lib/Numeric/GSL/Special/Clausen.hs +++ b/packages/special/lib/Numeric/GSL/Special/Clausen.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Clausen | 4 | -- Module : Numeric.GSL.Special.Clausen |
diff --git a/packages/special/lib/Numeric/GSL/Special/Coulomb.hs b/packages/special/lib/Numeric/GSL/Special/Coulomb.hs index 218213a..6904739 100644 --- a/packages/special/lib/Numeric/GSL/Special/Coulomb.hs +++ b/packages/special/lib/Numeric/GSL/Special/Coulomb.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Coulomb | 4 | -- Module : Numeric.GSL.Special.Coulomb |
diff --git a/packages/special/lib/Numeric/GSL/Special/Coupling.hs b/packages/special/lib/Numeric/GSL/Special/Coupling.hs index 326f53f..ad120cc 100644 --- a/packages/special/lib/Numeric/GSL/Special/Coupling.hs +++ b/packages/special/lib/Numeric/GSL/Special/Coupling.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Coupling | 4 | -- Module : Numeric.GSL.Special.Coupling |
diff --git a/packages/special/lib/Numeric/GSL/Special/Dawson.hs b/packages/special/lib/Numeric/GSL/Special/Dawson.hs index 9f73767..58d92a5 100644 --- a/packages/special/lib/Numeric/GSL/Special/Dawson.hs +++ b/packages/special/lib/Numeric/GSL/Special/Dawson.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Dawson | 4 | -- Module : Numeric.GSL.Special.Dawson |
diff --git a/packages/special/lib/Numeric/GSL/Special/Debye.hs b/packages/special/lib/Numeric/GSL/Special/Debye.hs index 7ca17e4..91f9f19 100644 --- a/packages/special/lib/Numeric/GSL/Special/Debye.hs +++ b/packages/special/lib/Numeric/GSL/Special/Debye.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Debye | 4 | -- Module : Numeric.GSL.Special.Debye |
diff --git a/packages/special/lib/Numeric/GSL/Special/Dilog.hs b/packages/special/lib/Numeric/GSL/Special/Dilog.hs index 32cceba..aaebd9f 100644 --- a/packages/special/lib/Numeric/GSL/Special/Dilog.hs +++ b/packages/special/lib/Numeric/GSL/Special/Dilog.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Dilog | 4 | -- Module : Numeric.GSL.Special.Dilog |
diff --git a/packages/special/lib/Numeric/GSL/Special/Elementary.hs b/packages/special/lib/Numeric/GSL/Special/Elementary.hs index e58a697..2c092cd 100644 --- a/packages/special/lib/Numeric/GSL/Special/Elementary.hs +++ b/packages/special/lib/Numeric/GSL/Special/Elementary.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Elementary | 4 | -- Module : Numeric.GSL.Special.Elementary |
diff --git a/packages/special/lib/Numeric/GSL/Special/Ellint.hs b/packages/special/lib/Numeric/GSL/Special/Ellint.hs index 365c366..678f6db 100644 --- a/packages/special/lib/Numeric/GSL/Special/Ellint.hs +++ b/packages/special/lib/Numeric/GSL/Special/Ellint.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Ellint | 4 | -- Module : Numeric.GSL.Special.Ellint |
diff --git a/packages/special/lib/Numeric/GSL/Special/Erf.hs b/packages/special/lib/Numeric/GSL/Special/Erf.hs index 171a3c5..ef96a18 100644 --- a/packages/special/lib/Numeric/GSL/Special/Erf.hs +++ b/packages/special/lib/Numeric/GSL/Special/Erf.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Erf | 4 | -- Module : Numeric.GSL.Special.Erf |
diff --git a/packages/special/lib/Numeric/GSL/Special/Exp.hs b/packages/special/lib/Numeric/GSL/Special/Exp.hs index 3b70078..b6dfeef 100644 --- a/packages/special/lib/Numeric/GSL/Special/Exp.hs +++ b/packages/special/lib/Numeric/GSL/Special/Exp.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Exp | 4 | -- Module : Numeric.GSL.Special.Exp |
diff --git a/packages/special/lib/Numeric/GSL/Special/Expint.hs b/packages/special/lib/Numeric/GSL/Special/Expint.hs index 06f4594..faef752 100644 --- a/packages/special/lib/Numeric/GSL/Special/Expint.hs +++ b/packages/special/lib/Numeric/GSL/Special/Expint.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Expint | 4 | -- Module : Numeric.GSL.Special.Expint |
diff --git a/packages/special/lib/Numeric/GSL/Special/Fermi_dirac.hs b/packages/special/lib/Numeric/GSL/Special/Fermi_dirac.hs index c39c096..fe45d53 100644 --- a/packages/special/lib/Numeric/GSL/Special/Fermi_dirac.hs +++ b/packages/special/lib/Numeric/GSL/Special/Fermi_dirac.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Fermi_dirac | 4 | -- Module : Numeric.GSL.Special.Fermi_dirac |
diff --git a/packages/special/lib/Numeric/GSL/Special/Gamma.hs b/packages/special/lib/Numeric/GSL/Special/Gamma.hs index 78115f1..41e24f0 100644 --- a/packages/special/lib/Numeric/GSL/Special/Gamma.hs +++ b/packages/special/lib/Numeric/GSL/Special/Gamma.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Gamma | 4 | -- Module : Numeric.GSL.Special.Gamma |
diff --git a/packages/special/lib/Numeric/GSL/Special/Gegenbauer.hs b/packages/special/lib/Numeric/GSL/Special/Gegenbauer.hs index a3c998a..fb8bf3f 100644 --- a/packages/special/lib/Numeric/GSL/Special/Gegenbauer.hs +++ b/packages/special/lib/Numeric/GSL/Special/Gegenbauer.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Gegenbauer | 4 | -- Module : Numeric.GSL.Special.Gegenbauer |
diff --git a/packages/special/lib/Numeric/GSL/Special/Hyperg.hs b/packages/special/lib/Numeric/GSL/Special/Hyperg.hs index ac237a5..3f63b8f 100644 --- a/packages/special/lib/Numeric/GSL/Special/Hyperg.hs +++ b/packages/special/lib/Numeric/GSL/Special/Hyperg.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Hyperg | 4 | -- Module : Numeric.GSL.Special.Hyperg |
diff --git a/packages/special/lib/Numeric/GSL/Special/Laguerre.hs b/packages/special/lib/Numeric/GSL/Special/Laguerre.hs index 28b3d20..919dc25 100644 --- a/packages/special/lib/Numeric/GSL/Special/Laguerre.hs +++ b/packages/special/lib/Numeric/GSL/Special/Laguerre.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Laguerre | 4 | -- Module : Numeric.GSL.Special.Laguerre |
diff --git a/packages/special/lib/Numeric/GSL/Special/Lambert.hs b/packages/special/lib/Numeric/GSL/Special/Lambert.hs index 44fbfb1..71ec9c2 100644 --- a/packages/special/lib/Numeric/GSL/Special/Lambert.hs +++ b/packages/special/lib/Numeric/GSL/Special/Lambert.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Lambert | 4 | -- Module : Numeric.GSL.Special.Lambert |
diff --git a/packages/special/lib/Numeric/GSL/Special/Legendre.hs b/packages/special/lib/Numeric/GSL/Special/Legendre.hs index cb33e2e..927fa2c 100644 --- a/packages/special/lib/Numeric/GSL/Special/Legendre.hs +++ b/packages/special/lib/Numeric/GSL/Special/Legendre.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Legendre | 4 | -- Module : Numeric.GSL.Special.Legendre |
diff --git a/packages/special/lib/Numeric/GSL/Special/Log.hs b/packages/special/lib/Numeric/GSL/Special/Log.hs index 3becf15..6111ed9 100644 --- a/packages/special/lib/Numeric/GSL/Special/Log.hs +++ b/packages/special/lib/Numeric/GSL/Special/Log.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Log | 4 | -- Module : Numeric.GSL.Special.Log |
diff --git a/packages/special/lib/Numeric/GSL/Special/Pow_int.hs b/packages/special/lib/Numeric/GSL/Special/Pow_int.hs index 08fd497..6f2540c 100644 --- a/packages/special/lib/Numeric/GSL/Special/Pow_int.hs +++ b/packages/special/lib/Numeric/GSL/Special/Pow_int.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Pow_int | 4 | -- Module : Numeric.GSL.Special.Pow_int |
diff --git a/packages/special/lib/Numeric/GSL/Special/Psi.hs b/packages/special/lib/Numeric/GSL/Special/Psi.hs index da53d1b..9e2e31a 100644 --- a/packages/special/lib/Numeric/GSL/Special/Psi.hs +++ b/packages/special/lib/Numeric/GSL/Special/Psi.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Psi | 4 | -- Module : Numeric.GSL.Special.Psi |
diff --git a/packages/special/lib/Numeric/GSL/Special/Synchrotron.hs b/packages/special/lib/Numeric/GSL/Special/Synchrotron.hs index b3292a6..c518c30 100644 --- a/packages/special/lib/Numeric/GSL/Special/Synchrotron.hs +++ b/packages/special/lib/Numeric/GSL/Special/Synchrotron.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Synchrotron | 4 | -- Module : Numeric.GSL.Special.Synchrotron |
diff --git a/packages/special/lib/Numeric/GSL/Special/Transport.hs b/packages/special/lib/Numeric/GSL/Special/Transport.hs index b92b578..0047104 100644 --- a/packages/special/lib/Numeric/GSL/Special/Transport.hs +++ b/packages/special/lib/Numeric/GSL/Special/Transport.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Transport | 4 | -- Module : Numeric.GSL.Special.Transport |
diff --git a/packages/special/lib/Numeric/GSL/Special/Trig.hs b/packages/special/lib/Numeric/GSL/Special/Trig.hs index 43fdc95..f2c1519 100644 --- a/packages/special/lib/Numeric/GSL/Special/Trig.hs +++ b/packages/special/lib/Numeric/GSL/Special/Trig.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Trig | 4 | -- Module : Numeric.GSL.Special.Trig |
diff --git a/packages/special/lib/Numeric/GSL/Special/Zeta.hs b/packages/special/lib/Numeric/GSL/Special/Zeta.hs index a57a918..53a6314 100644 --- a/packages/special/lib/Numeric/GSL/Special/Zeta.hs +++ b/packages/special/lib/Numeric/GSL/Special/Zeta.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | ------------------------------------------------------------ | 2 | ------------------------------------------------------------ |
2 | -- | | 3 | -- | |
3 | -- Module : Numeric.GSL.Special.Zeta | 4 | -- Module : Numeric.GSL.Special.Zeta |
diff --git a/packages/tests/hmatrix-tests.cabal b/packages/tests/hmatrix-tests.cabal index d4c87aa..00f3a38 100644 --- a/packages/tests/hmatrix-tests.cabal +++ b/packages/tests/hmatrix-tests.cabal | |||
@@ -29,6 +29,7 @@ library | |||
29 | Build-Depends: base >= 4 && < 5, deepseq, | 29 | Build-Depends: base >= 4 && < 5, deepseq, |
30 | QuickCheck >= 2, HUnit, random, | 30 | QuickCheck >= 2, HUnit, random, |
31 | hmatrix >= 0.18 | 31 | hmatrix >= 0.18 |
32 | , binary | ||
32 | if flag(gsl) | 33 | if flag(gsl) |
33 | Build-Depends: hmatrix-gsl >= 0.18 | 34 | Build-Depends: hmatrix-gsl >= 0.18 |
34 | 35 | ||
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs index d9cc3b6..043ebf3 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs | |||
@@ -26,6 +26,7 @@ module Numeric.LinearAlgebra.Tests( | |||
26 | utest, | 26 | utest, |
27 | runTests, | 27 | runTests, |
28 | runBenchmarks | 28 | runBenchmarks |
29 | , binaryTests | ||
29 | -- , findNaN | 30 | -- , findNaN |
30 | --, runBigTests | 31 | --, runBigTests |
31 | ) where | 32 | ) where |
@@ -743,6 +744,15 @@ makeUnitary v | realPart n > 1 = v / scalar n | |||
743 | | otherwise = v | 744 | | otherwise = v |
744 | where n = sqrt (v `dot` v) | 745 | where n = sqrt (v `dot` v) |
745 | 746 | ||
747 | binaryTests :: IO () | ||
748 | binaryTests = do | ||
749 | let test :: forall t . T.Testable t => t -> IO () | ||
750 | test = qCheck 100 | ||
751 | test vectorBinaryRoundtripProp | ||
752 | test staticVectorBinaryRoundtripProp | ||
753 | qCheck 30 matrixBinaryRoundtripProp | ||
754 | qCheck 30 staticMatrixBinaryRoundtripProp | ||
755 | |||
746 | -- -- | Some additional tests on big matrices. They take a few minutes. | 756 | -- -- | Some additional tests on big matrices. They take a few minutes. |
747 | -- runBigTests :: IO () | 757 | -- runBigTests :: IO () |
748 | -- runBigTests = undefined | 758 | -- runBigTests = undefined |
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs index 3d5441d..23d7e6f 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests/Instances.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | {-# LANGUAGE FlexibleContexts, UndecidableInstances, FlexibleInstances #-} | 1 | {-# LANGUAGE FlexibleContexts, UndecidableInstances, FlexibleInstances, ScopedTypeVariables #-} |
2 | ----------------------------------------------------------------------------- | 2 | ----------------------------------------------------------------------------- |
3 | {- | | 3 | {- | |
4 | Module : Numeric.LinearAlgebra.Tests.Instances | 4 | Module : Numeric.LinearAlgebra.Tests.Instances |
@@ -29,6 +29,10 @@ import Numeric.LinearAlgebra.HMatrix hiding (vector) | |||
29 | import Control.Monad(replicateM) | 29 | import Control.Monad(replicateM) |
30 | import Test.QuickCheck(Arbitrary,arbitrary,choose,vector,sized,shrink) | 30 | import Test.QuickCheck(Arbitrary,arbitrary,choose,vector,sized,shrink) |
31 | 31 | ||
32 | import GHC.TypeLits | ||
33 | import Data.Proxy (Proxy) | ||
34 | import qualified Numeric.LinearAlgebra.Static as Static | ||
35 | |||
32 | 36 | ||
33 | shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] | 37 | shrinkListElementwise :: (Arbitrary a) => [a] -> [[a]] |
34 | shrinkListElementwise [] = [] | 38 | shrinkListElementwise [] = [] |
@@ -40,14 +44,27 @@ shrinkPair (a,b) = [ (a,x) | x <- shrink b ] ++ [ (x,b) | x <- shrink a ] | |||
40 | 44 | ||
41 | chooseDim = sized $ \m -> choose (1,max 1 m) | 45 | chooseDim = sized $ \m -> choose (1,max 1 m) |
42 | 46 | ||
43 | instance (Field a, Arbitrary a) => Arbitrary (Vector a) where | 47 | instance (Field a, Arbitrary a) => Arbitrary (Vector a) where |
44 | arbitrary = do m <- chooseDim | 48 | arbitrary = do m <- chooseDim |
45 | l <- vector m | 49 | l <- vector m |
46 | return $ fromList l | 50 | return $ fromList l |
47 | -- shrink any one of the components | 51 | -- shrink any one of the components |
48 | shrink = map fromList . shrinkListElementwise . toList | 52 | shrink = map fromList . shrinkListElementwise . toList |
49 | 53 | ||
50 | instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where | 54 | instance KnownNat n => Arbitrary (Static.R n) where |
55 | arbitrary = do | ||
56 | l <- vector n | ||
57 | return (Static.fromList l) | ||
58 | |||
59 | where proxy :: Proxy n | ||
60 | proxy = proxy | ||
61 | |||
62 | n :: Int | ||
63 | n = fromIntegral (natVal proxy) | ||
64 | |||
65 | shrink v = [] | ||
66 | |||
67 | instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where | ||
51 | arbitrary = do | 68 | arbitrary = do |
52 | m <- chooseDim | 69 | m <- chooseDim |
53 | n <- chooseDim | 70 | n <- chooseDim |
@@ -57,9 +74,28 @@ instance (Element a, Arbitrary a) => Arbitrary (Matrix a) where | |||
57 | -- shrink any one of the components | 74 | -- shrink any one of the components |
58 | shrink a = map (rows a >< cols a) | 75 | shrink a = map (rows a >< cols a) |
59 | . shrinkListElementwise | 76 | . shrinkListElementwise |
60 | . concat . toLists | 77 | . concat . toLists |
61 | $ a | 78 | $ a |
62 | 79 | ||
80 | instance (KnownNat n, KnownNat m) => Arbitrary (Static.L m n) where | ||
81 | arbitrary = do | ||
82 | l <- vector (m * n) | ||
83 | return (Static.fromList l) | ||
84 | |||
85 | where proxyM :: Proxy m | ||
86 | proxyM = proxyM | ||
87 | |||
88 | proxyN :: Proxy n | ||
89 | proxyN = proxyN | ||
90 | |||
91 | m :: Int | ||
92 | m = fromIntegral (natVal proxyM) | ||
93 | |||
94 | n :: Int | ||
95 | n = fromIntegral (natVal proxyN) | ||
96 | |||
97 | shrink mat = [] | ||
98 | |||
63 | -- a square matrix | 99 | -- a square matrix |
64 | newtype (Sq a) = Sq (Matrix a) deriving Show | 100 | newtype (Sq a) = Sq (Matrix a) deriving Show |
65 | instance (Element a, Arbitrary a) => Arbitrary (Sq a) where | 101 | instance (Element a, Arbitrary a) => Arbitrary (Sq a) where |
@@ -121,7 +157,7 @@ instance (ArbitraryField a, Numeric a) => Arbitrary (SqWC a) where | |||
121 | 157 | ||
122 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) | 158 | -- a positive definite square matrix (the eigenvalues are between 0 and 100) |
123 | newtype (PosDef a) = PosDef (Matrix a) deriving Show | 159 | newtype (PosDef a) = PosDef (Matrix a) deriving Show |
124 | instance (Numeric a, ArbitraryField a, Num (Vector a)) | 160 | instance (Numeric a, ArbitraryField a, Num (Vector a)) |
125 | => Arbitrary (PosDef a) where | 161 | => Arbitrary (PosDef a) where |
126 | arbitrary = do | 162 | arbitrary = do |
127 | m <- arbitrary | 163 | m <- arbitrary |
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 | ||