@@ -14,12 +14,17 @@ import Control.Monad ( guard )
1414import Control.Monad.ST ( runST )
1515
1616import Data.Constraint
17+#if __GLASGOW_HASKELL__ < 800
18+import Data.Proxy
19+#endif
1720import qualified Data.Vector.Storable as VS
1821import qualified Data.Vector.Storable.Mutable as VS ( write )
1922import Data.Singletons
2023import Data.Singletons.Prelude.List
2124import Data.Singletons.TypeLits
2225
26+-- import Data.Type.Equality
27+
2328import Hedgehog
2429import qualified Hedgehog.Gen as Gen
2530import Hedgehog.Internal.Source
@@ -27,15 +32,7 @@ import Hedgehog.Internal.Property ( failWith )
2732
2833import Grenade
2934
30−#if MIN_VERSION_base(4,11,0)
31−import GHC.TypeLits hiding (natVal)
32−#else
3335import GHC.TypeLits
34−#endif
35−#if MIN_VERSION_base(4,9,0)
36−import Data.Kind (Type)
37−#endif
38−
3936import GHC.TypeLits.Witnesses
4037import Test.Hedgehog.Compat
4138import Test.Hedgehog.TypeLits
@@ -46,7 +43,7 @@ import Numeric.LinearAlgebra ( flatten )
4643import Numeric.LinearAlgebra.Static ( extract, norm_Inf )
4744import Unsafe.Coerce
4845
49−data SomeNetwork :: Type where
46+data SomeNetwork :: * where
5047 SomeNetwork :: ( SingI shapes, SingI (Head shapes), SingI (Last shapes), Show (Network layers shapes) ) => Network layers shapes -> SomeNetwork
5148
5249instance Show SomeNetwork where
@@ -77,9 +74,8 @@ genNetwork =
7774 , pure (SomeNetwork (Elu :~> rest :: Network ( Elu ': layers ) ( h ': h ': hs )))
7875 , pure (SomeNetwork (Softmax :~> rest :: Network ( Softmax ': layers ) ( h ': h ': hs )))
7976 , do -- Reshape to two dimensions
80− let divisors :: Integer -> [Integer]
81− divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
82− let len = fromIntegral $ natVal l
77+ let divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
78+ let len = natVal l
8379 rs <- Gen.element $ divisors len
8480 let cs = len `quot` rs
8581 case ( someNatVal rs, someNatVal cs, someNatVal len ) of
@@ -100,8 +96,8 @@ genNetwork =
10096 , do -- Build a convolution layer with one filter output
10197 -- Figure out some kernel sizes which work for this layer
10298 -- There must be a better way than this...
103− let output_r = fromIntegral $ natVal r
104− let output_c = fromIntegral $ natVal c
99+ let output_r = natVal r
100+ let output_c = natVal c
105101
106102 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
107103
@@ -140,8 +136,8 @@ genNetwork =
140136 , do -- Build a convolution layer with one filter output
141137 -- Figure out some kernel sizes which work for this layer
142138 -- There must be a better way than this...
143− let output_r = fromIntegral $ natVal r
144− let output_c = fromIntegral $ natVal c
139+ let output_r = natVal r
140+ let output_c = natVal c
145141
146142 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
147143
@@ -182,8 +178,8 @@ genNetwork =
182178 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels 1 kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
183179 _ -> Gen.discard -- Can't occur
184180 , do -- Build a Pooling layer
185− let output_r = fromIntegral $ natVal r
186− let output_c = fromIntegral $ natVal c
181+ let output_r = natVal r
182+ let output_c = natVal c
187183
188184 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
189185
@@ -219,8 +215,8 @@ genNetwork =
219215 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D2 inRows inCols) ': h ': hs )))
220216 _ -> Gen.discard -- Can't occur
221217 , do -- Build a Pad layer
222− let output_r = fromIntegral $ natVal r
223− let output_c = fromIntegral $ natVal c
218+ let output_r = natVal r
219+ let output_c = natVal c
224220
225221 pad_left <- choose 0 (output_r - 1)
226222 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -246,8 +242,8 @@ genNetwork =
246242 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D2 inputRows inputColumns) ': h ': hs )))
247243 _ -> Gen.discard -- Can't occur
248244 , do -- Build a Crop layer
249− let output_r = fromIntegral $ natVal r
250− let output_c = fromIntegral $ natVal c
245+ let output_r = natVal r
246+ let output_c = natVal c
251247
252248 crop_left <- choose 0 10
253249 crop_right <- choose 0 10
@@ -279,9 +275,9 @@ genNetwork =
279275 , do -- Build a convolution layer with one filter output
280276 -- Figure out some kernel sizes which work for this layer
281277 -- There must be a better way than this...
282− let output_r = fromIntegral $ natVal r
283− let output_c = fromIntegral $ natVal c
284− let output_f = fromIntegral $ natVal f
278+ let output_r = natVal r
279+ let output_c = natVal c
280+ let output_f = natVal f
285281
286282 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
287283
@@ -322,9 +318,9 @@ genNetwork =
322318 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels filters kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
323319 _ -> Gen.discard -- Can't occur
324320 , do -- Build a Pooling layer
325− let output_r = fromIntegral $ natVal r
326− let output_c = fromIntegral $ natVal c
327− let output_f = fromIntegral $ natVal f
321+ let output_r = natVal r
322+ let output_c = natVal c
323+ let output_f = natVal f
328324
329325 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
330326
@@ -363,9 +359,9 @@ genNetwork =
363359 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols filters) ': h ': hs )))
364360 _ -> Gen.discard -- Can't occur
365361 , do -- Build a Pad layer
366− let output_r = fromIntegral $ natVal r
367− let output_c = fromIntegral $ natVal c
368− let output_f = fromIntegral $ natVal f
362+ let output_r = natVal r
363+ let output_c = natVal c
364+ let output_f = natVal f
369365
370366 pad_left <- choose 0 (output_r - 1)
371367 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -393,9 +389,9 @@ genNetwork =
393389 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D3 inputRows inputColumns filters) ': h ': hs )))
394390 _ -> Gen.discard -- Can't occur
395391 , do -- Build a Crop layer
396− let output_r = fromIntegral $ natVal r
397− let output_c = fromIntegral $ natVal c
398− let output_f = fromIntegral $ natVal f
392+ let output_r = natVal r
393+ let output_c = natVal c
394+ let output_f = natVal f
399395
400396 crop_left <- choose 0 10
401397 crop_right <- choose 0 10
@@ -448,7 +444,7 @@ oneUp =
448444 D1Sing SNat ->
449445 let x = 0 :: S ( shape )
450446 in case x of
451− ( S1D x' ) -> do
447+ ( S1D x' ) -> do
452448 let ex = extract x'
453449 let len = VS.length ex
454450 ix <- choose 0 (len - 1)
@@ -460,7 +456,7 @@ oneUp =
460456 D2Sing SNat SNat ->
461457 let x = 0 :: S ( shape )
462458 in case x of
463− ( S2D x' ) -> do
459+ ( S2D x' ) -> do
464460 let ex = flatten ( extract x' )
465461 let len = VS.length ex
466462 ix <- choose 0 (len - 1)
@@ -472,7 +468,7 @@ oneUp =
472468 D3Sing SNat SNat SNat ->
473469 let x = 0 :: S ( shape )
474470 in case x of
475− ( S3D x' ) -> do
471+ ( S3D x' ) -> do
476472 let ex = flatten ( extract x' )
477473 let len = VS.length ex
478474 ix <- choose 0 (len - 1)