@@ -73,6 +73,19 @@ genNetwork =
7373 , pure (SomeNetwork (Relu :~> rest :: Network ( Relu ': layers ) ( h ': h ': hs )))
7474 , pure (SomeNetwork (Elu :~> rest :: Network ( Elu ': layers ) ( h ': h ': hs )))
7575 , pure (SomeNetwork (Softmax :~> rest :: Network ( Softmax ': layers ) ( h ': h ': hs )))
76+ , do -- Reshape to two dimensions
77+ let divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
78+ let len = natVal l
79+ rs <- Gen.element $ divisors len
80+ let cs = len `quot` rs
81+ case ( someNatVal rs, someNatVal cs, someNatVal len ) of
82+ ( Just (SomeNat (rs' :: Proxy inRows)), Just (SomeNat (cs' :: Proxy inCols)), Just (SomeNat (_ :: Proxy outLen ) )) ->
83+ let p1 = natDict rs'
84+ p2 = natDict cs'
85+ in case ( p1 %* p2, unsafeCoerce (Dict :: Dict ()) :: Dict ((inRows * inCols) ~ outLen), unsafeCoerce (Dict :: Dict ()) :: Dict (( 'D1 outLen ) ~ h )) of
86+ ( Dict, Dict, Dict ) ->
87+ pure (SomeNetwork (Reshape :~> rest :: Network ( Reshape ': layers ) ( ('D2 inRows inCols) ': h ': hs )))
88+ _ -> Gen.discard -- Doesn't occur
7689 ]
7790 D2Sing r c -> withKnownNat r $ withKnownNat c $
7891 Gen.choice [