on master help sign in
Add serialisation for Concat and Merge
235b767Huw Campbell
src/Grenade/Layers/Concat.hs+6
@@ -21,6 +21,8 @@ module Grenade.Layers.Concat (
21 Concat (..)
21 Concat (..)
22 ) where
22 ) where
23
23
24+import Data.Serialize
25+
24import Data.Singletons
26import Data.Singletons
25import GHC.TypeLits
27import GHC.TypeLits
26
28
@@ -125,3 +127,7 @@ instance ( SingI i
125 (x', xB :: S i) = runBackwards x xTape (S3D ox :: S ('D3 rows cols m))
127 (x', xB :: S i) = runBackwards x xTape (S3D ox :: S ('D3 rows cols m))
126 (y', yB :: S i) = runBackwards y yTape (S3D oy :: S ('D3 rows cols n))
128 (y', yB :: S i) = runBackwards y yTape (S3D oy :: S ('D3 rows cols n))
127 in ((x', y'), xB + yB)
129 in ((x', y'), xB + yB)
130+
131+instance (Serialize a, Serialize b) => Serialize (Concat sa a sb b) where
132+ put (Concat a b) = put a *> put b
133+ get = Concat <$> get <*> get
src/Grenade/Layers/Merge.hs+6
@@ -19,6 +19,8 @@ module Grenade.Layers.Merge (
19 Merge (..)
19 Merge (..)
20 ) where
20 ) where
21
21
22+import Data.Serialize
23+
22import Data.Singletons
24import Data.Singletons
23
25
24import Grenade.Core
26import Grenade.Core
@@ -53,3 +55,7 @@ instance (SingI i, SingI o, Layer x i o, Layer y i o) => Layer (Merge x y) i o w
53 let (x', xB) = runBackwards x xTape o
55 let (x', xB) = runBackwards x xTape o
54 (y', yB) = runBackwards y yTape o
56 (y', yB) = runBackwards y yTape o
55 in ((x', y'), xB + yB)
57 in ((x', y'), xB + yB)
58+
59+instance (Serialize a, Serialize b) => Serialize (Merge a b) where
60+ put (Merge a b) = put a *> put b
61+ get = Merge <$> get <*> get