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/base/src | |
parent | 95c7cc6303fdb0af3ca0e1fc08cfe3ebf2674814 (diff) |
some work (will probably undo this commit later)
Diffstat (limited to 'packages/base/src')
-rw-r--r-- | packages/base/src/Internal/Matrix.hs | 1 | ||||
-rw-r--r-- | packages/base/src/Internal/Static.hs | 25 |
2 files changed, 22 insertions, 4 deletions
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 |