on master help sign in
Add serialisation for Concat and Merge
commit235b76763a76dca14a515df5af79fce5a637819b authorHuw Campbell <huw.campbell@ambiata.com> dateThu 6 Apr 2017, 16:29 (10 years ago) parent10a6003
2 files changed+12
src/Grenade/Layers/Concat.hs+6 src/Grenade/Layers/Merge.hs+6
src/Grenade/Layers/Concat.hs+6
@@ -21,6 +21,8 @@ module Grenade.Layers.Concat (
2121 Concat (..)
2222 ) where
2323
24+import Data.Serialize
25+
2426import Data.Singletons
2527import GHC.TypeLits
2628
@@ -125,3 +127,7 @@ instance ( SingI i
125127 (x', xB :: S i) = runBackwards x xTape (S3D ox :: S ('D3 rows cols m))
126128 (y', yB :: S i) = runBackwards y yTape (S3D oy :: S ('D3 rows cols n))
127129 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 (
1919 Merge (..)
2020 ) where
2121
22+import Data.Serialize
23+
2224import Data.Singletons
2325
2426import 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
5355 let (x', xB) = runBackwards x xTape o
5456 (y', yB) = runBackwards y yTape o
5557 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