@@ -44,6 +44,7 @@ import Data.Kind (Type)
4444import Grenade.Core.Layer
4545import Grenade.Core.LearningParameters
4646import Grenade.Core.Shape
47+import Control.DeepSeq
4748
4849-- | Type of a network.
4950--
@@ -68,6 +69,12 @@ instance Show (Network '[] '[i]) where
6869instance (Show x, Show (Network xs rs)) => Show (Network (x ': xs) (i ': rs)) where
6970 show (x :~> xs) = show x ++ "\n~>\n" ++ show xs
7071
72+instance NFData (Network '[] '[i]) where
73+ rnf NNil = ()
74+
75+instance NFData (Network xs rs) => NFData (Network (x ': xs) (i ': rs)) where
76+ rnf (x :~> xs) = x `deepseq` xs `deepseq` ()
77+
7178-- | Gradient of a network.
7279--
7380-- Parameterised on the layers of the network.
@@ -191,7 +198,7 @@ instance CreatableNetwork sublayers subshapes => UpdateLayer (Network sublayers
191198-- | Ultimate composition.
192199--
193200-- This allows a complete network to be treated as a layer in a larger network.
194−instance (CreatableNetwork sublayers subshapes, i ~ (Head subshapes), o ~ (Last subshapes)) => Layer (Network sublayers subshapes) i o where
201+instance (CreatableNetwork sublayers subshapes, i ~ (Head subshapes), o ~ (Last subshapes), NFData (Network sublayers subshapes)) => Layer (Network sublayers subshapes) i o where
195202 type Tape (Network sublayers subshapes) i o = Tapes sublayers subshapes
196203 runForwards = runNetwork
197204 runBackwards = runGradient