@@ -23,8 +23,6 @@ import Data.Singletons
23import Data.Singletons.Prelude.List
23import Data.Singletons.Prelude.List
24import Data.Singletons.TypeLits
24import Data.Singletons.TypeLits
26−-- import Data.Type.Equality
28import Hedgehog
26import Hedgehog
29import qualified Hedgehog.Gen as Gen
27import qualified Hedgehog.Gen as Gen
30import Hedgehog.Internal.Source
28import Hedgehog.Internal.Source
@@ -32,7 +30,12 @@ import Hedgehog.Internal.Property ( failWith )
33import Grenade
31import Grenade
33+#if MIN_VERSION_base(4,11,0)
34+import GHC.TypeLits hiding (natVal)
35import GHC.TypeLits
36import GHC.TypeLits
36import GHC.TypeLits.Witnesses
39import GHC.TypeLits.Witnesses
37import Test.Hedgehog.Compat
40import Test.Hedgehog.Compat
38import Test.Hedgehog.TypeLits
41import Test.Hedgehog.TypeLits
@@ -74,8 +77,9 @@ genNetwork =
74 , pure (SomeNetwork (Elu :~> rest :: Network ( Elu ': layers ) ( h ': h ': hs )))
77 , pure (SomeNetwork (Elu :~> rest :: Network ( Elu ': layers ) ( h ': h ': hs )))
75 , pure (SomeNetwork (Softmax :~> rest :: Network ( Softmax ': layers ) ( h ': h ': hs )))
78 , pure (SomeNetwork (Softmax :~> rest :: Network ( Softmax ': layers ) ( h ': h ': hs )))
76 , do -- Reshape to two dimensions
79 , do -- Reshape to two dimensions
80+ let divisors :: Integer -> [Integer]
77− let divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
81+ divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
78− let len = natVal l
82+ let len = fromIntegral $ natVal l
79 rs <- Gen.element $ divisors len
83 rs <- Gen.element $ divisors len
80 let cs = len `quot` rs
84 let cs = len `quot` rs
81 case ( someNatVal rs, someNatVal cs, someNatVal len ) of
85 case ( someNatVal rs, someNatVal cs, someNatVal len ) of
@@ -96,8 +100,8 @@ genNetwork =
96 , do -- Build a convolution layer with one filter output
100 , do -- Build a convolution layer with one filter output
97 -- Figure out some kernel sizes which work for this layer
101 -- Figure out some kernel sizes which work for this layer
98 -- There must be a better way than this...
102 -- There must be a better way than this...
99− let output_r = natVal r
103+ let output_r = fromIntegral $ natVal r
100− let output_c = natVal c
104+ let output_c = fromIntegral $ natVal c
102 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
106 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
@@ -136,8 +140,8 @@ genNetwork =
136 , do -- Build a convolution layer with one filter output
140 , do -- Build a convolution layer with one filter output
137 -- Figure out some kernel sizes which work for this layer
141 -- Figure out some kernel sizes which work for this layer
138 -- There must be a better way than this...
142 -- There must be a better way than this...
139− let output_r = natVal r
143+ let output_r = fromIntegral $ natVal r
140− let output_c = natVal c
144+ let output_c = fromIntegral $ natVal c
142 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
146 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
@@ -178,8 +182,8 @@ genNetwork =
178 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels 1 kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
182 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels 1 kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
179 _ -> Gen.discard -- Can't occur
183 _ -> Gen.discard -- Can't occur
180 , do -- Build a Pooling layer
184 , do -- Build a Pooling layer
181− let output_r = natVal r
185+ let output_r = fromIntegral $ natVal r
182− let output_c = natVal c
186+ let output_c = fromIntegral $ natVal c
184 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
188 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
@@ -215,8 +219,8 @@ genNetwork =
215 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D2 inRows inCols) ': h ': hs )))
219 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D2 inRows inCols) ': h ': hs )))
216 _ -> Gen.discard -- Can't occur
220 _ -> Gen.discard -- Can't occur
217 , do -- Build a Pad layer
221 , do -- Build a Pad layer
218− let output_r = natVal r
222+ let output_r = fromIntegral $ natVal r
219− let output_c = natVal c
223+ let output_c = fromIntegral $ natVal c
221 pad_left <- choose 0 (output_r - 1)
225 pad_left <- choose 0 (output_r - 1)
222 pad_right <- choose 0 (output_r - 1 - pad_left)
226 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -242,8 +246,8 @@ genNetwork =
242 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D2 inputRows inputColumns) ': h ': hs )))
246 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D2 inputRows inputColumns) ': h ': hs )))
243 _ -> Gen.discard -- Can't occur
247 _ -> Gen.discard -- Can't occur
244 , do -- Build a Crop layer
248 , do -- Build a Crop layer
245− let output_r = natVal r
249+ let output_r = fromIntegral $ natVal r
246− let output_c = natVal c
250+ let output_c = fromIntegral $ natVal c
248 crop_left <- choose 0 10
252 crop_left <- choose 0 10
249 crop_right <- choose 0 10
253 crop_right <- choose 0 10
@@ -275,9 +279,9 @@ genNetwork =
275 , do -- Build a convolution layer with one filter output
279 , do -- Build a convolution layer with one filter output
276 -- Figure out some kernel sizes which work for this layer
280 -- Figure out some kernel sizes which work for this layer
277 -- There must be a better way than this...
281 -- There must be a better way than this...
278− let output_r = natVal r
282+ let output_r = fromIntegral $ natVal r
279− let output_c = natVal c
283+ let output_c = fromIntegral $ natVal c
280− let output_f = natVal f
284+ let output_f = fromIntegral $ natVal f
282 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
286 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
@@ -318,9 +322,9 @@ genNetwork =
318 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels filters kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
322 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels filters kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
319 _ -> Gen.discard -- Can't occur
323 _ -> Gen.discard -- Can't occur
320 , do -- Build a Pooling layer
324 , do -- Build a Pooling layer
321− let output_r = natVal r
325+ let output_r = fromIntegral $ natVal r
322− let output_c = natVal c
326+ let output_c = fromIntegral $ natVal c
323− let output_f = natVal f
327+ let output_f = fromIntegral $ natVal f
325 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
329 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
@@ -359,9 +363,9 @@ genNetwork =
359 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols filters) ': h ': hs )))
363 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols filters) ': h ': hs )))
360 _ -> Gen.discard -- Can't occur
364 _ -> Gen.discard -- Can't occur
361 , do -- Build a Pad layer
365 , do -- Build a Pad layer
362− let output_r = natVal r
366+ let output_r = fromIntegral $ natVal r
363− let output_c = natVal c
367+ let output_c = fromIntegral $ natVal c
364− let output_f = natVal f
368+ let output_f = fromIntegral $ natVal f
366 pad_left <- choose 0 (output_r - 1)
370 pad_left <- choose 0 (output_r - 1)
367 pad_right <- choose 0 (output_r - 1 - pad_left)
371 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -389,9 +393,9 @@ genNetwork =
389 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D3 inputRows inputColumns filters) ': h ': hs )))
393 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D3 inputRows inputColumns filters) ': h ': hs )))
390 _ -> Gen.discard -- Can't occur
394 _ -> Gen.discard -- Can't occur
391 , do -- Build a Crop layer
395 , do -- Build a Crop layer
392− let output_r = natVal r
396+ let output_r = fromIntegral $ natVal r
393− let output_c = natVal c
397+ let output_c = fromIntegral $ natVal c
394− let output_f = natVal f
398+ let output_f = fromIntegral $ natVal f
396 crop_left <- choose 0 10
400 crop_left <- choose 0 10
397 crop_right <- choose 0 10
401 crop_right <- choose 0 10