on master help sign in
Merge pull request #75 from erikd/master
950be38Huw Campbell
.travis.yml+2−1
@@ -4,7 +4,8 @@
4env:
4env:
5 - CABALVER=1.22 GHCVER=7.10.3
5 - CABALVER=1.22 GHCVER=7.10.3
6 - CABALVER=1.24 GHCVER=8.0.2
6 - CABALVER=1.24 GHCVER=8.0.2
7− - CABALVER=2.0 GHCVER=8.2.1
7+ - CABALVER=2.0 GHCVER=8.2.2
8+ - CABALVER=2.0 GHCVER=8.4.3
8
9
9# Note: the distinction between `before_install` and `install` is not important.
10# Note: the distinction between `before_install` and `install` is not important.
10before_install:
11before_install:
README.md+1−1
@@ -159,7 +159,7 @@ and the tests run using:
159./mafia test
159./mafia test
160```
160```
161
161
162−Grenade builds with ghc 7.10 and 8.0.
162+Grenade builds with ghc 7.10, 8.0, 8.2 and 8.4.
163
163
164Thanks
164Thanks
165------
165------
grenade.cabal+11−9
@@ -45,7 +45,9 @@ library
45 , hmatrix == 0.18.*
45 , hmatrix == 0.18.*
46 , MonadRandom >= 0.4 && < 0.6
46 , MonadRandom >= 0.4 && < 0.6
47 , primitive >= 0.6 && < 0.7
47 , primitive >= 0.6 && < 0.7
48+ -- Versions of singletons are *tightly* coupled with the
49+ -- GHC version so its fine to drop version bounds.
48− , singletons >= 2.1 && < 2.4
50+ , singletons
49 , vector >= 0.11 && < 0.13
51 , vector >= 0.11 && < 0.13
50
52
51 ghc-options:
53 ghc-options:
@@ -146,9 +148,9 @@ test-suite test
146 ghc-options: -fno-warn-incomplete-patterns
148 ghc-options: -fno-warn-incomplete-patterns
147
149
148 build-depends:
150 build-depends:
149− base >= 4.8 && < 5
151+ base
150 , grenade
152 , grenade
151− , hedgehog >= 0.5 && < 0.6
153+ , hedgehog >= 0.5 && < 0.7
152 , hmatrix
154 , hmatrix
153 , mtl
155 , mtl
154 , singletons
156 , singletons
@@ -174,9 +176,9 @@ benchmark bench
174 bench
176 bench
175
177
176 build-depends:
178 build-depends:
177− base >= 3 && < 5
179+ base
178− , bytestring == 0.10.*
180+ , bytestring
179− , criterion >= 1.1 && < 1.3
181+ , criterion >= 1.1 && < 1.5
180 , grenade
182 , grenade
181 , hmatrix
183 , hmatrix
182
184
@@ -191,8 +193,8 @@ benchmark bench-lstm
191 bench
193 bench
192
194
193 build-depends:
195 build-depends:
194− base >= 3 && < 5
196+ base
195− , bytestring == 0.10.*
197+ , bytestring
196− , criterion == 1.1.*
198+ , criterion
197 , grenade
199 , grenade
198 , hmatrix
200 , hmatrix
src/Grenade/Core/Shape.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE GADTs #-}
3{-# LANGUAGE GADTs #-}
3{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE KindSignatures #-}
@@ -35,7 +36,11 @@ import Data.Singletons.TypeLits
35import Data.Vector.Storable ( Vector )
36import Data.Vector.Storable ( Vector )
36import qualified Data.Vector.Storable as V
37import qualified Data.Vector.Storable as V
37
38
39+#if MIN_VERSION_base(4,11,0)
40+import GHC.TypeLits hiding (natVal)
41+#else
38import GHC.TypeLits
42import GHC.TypeLits
43+#endif
39
44
40import qualified Numeric.LinearAlgebra.Static as H
45import qualified Numeric.LinearAlgebra.Static as H
41import Numeric.LinearAlgebra.Static
46import Numeric.LinearAlgebra.Static
src/Grenade/Layers/Convolution.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE RecordWildCards #-}
4{-# LANGUAGE RecordWildCards #-}
@@ -29,7 +30,11 @@ import Data.Proxy
29import Data.Serialize
30import Data.Serialize
30import Data.Singletons.TypeLits
31import Data.Singletons.TypeLits
31
32
33+#if MIN_VERSION_base(4,11,0)
34+import GHC.TypeLits hiding (natVal)
35+#else
32import GHC.TypeLits
36import GHC.TypeLits
37+#endif
33
38
34import Numeric.LinearAlgebra hiding ( uniformSample, konst )
39import Numeric.LinearAlgebra hiding ( uniformSample, konst )
35import qualified Numeric.LinearAlgebra as LA
40import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Crop.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
@@ -20,7 +21,12 @@ import Data.Maybe
20import Data.Proxy
21import Data.Proxy
21import Data.Serialize
22import Data.Serialize
22import Data.Singletons.TypeLits
23import Data.Singletons.TypeLits
24+
25+#if MIN_VERSION_base(4,11,0)
26+import GHC.TypeLits hiding (natVal)
27+#else
23import GHC.TypeLits
28import GHC.TypeLits
29+#endif
24
30
25import Grenade.Core
31import Grenade.Core
26import Grenade.Layers.Internal.Pad
32import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Deconvolution.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE RecordWildCards #-}
4{-# LANGUAGE RecordWildCards #-}
@@ -33,7 +34,11 @@ import Data.Proxy
33import Data.Serialize
34import Data.Serialize
34import Data.Singletons.TypeLits
35import Data.Singletons.TypeLits
35
36
37+#if MIN_VERSION_base(4,11,0)
38+import GHC.TypeLits hiding (natVal)
39+#else
36import GHC.TypeLits
40import GHC.TypeLits
41+#endif
37
42
38import Numeric.LinearAlgebra hiding ( uniformSample, konst )
43import Numeric.LinearAlgebra hiding ( uniformSample, konst )
39import qualified Numeric.LinearAlgebra as LA
44import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Pad.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
@@ -20,7 +21,12 @@ import Data.Maybe
20import Data.Proxy
21import Data.Proxy
21import Data.Serialize
22import Data.Serialize
22import Data.Singletons.TypeLits
23import Data.Singletons.TypeLits
24+
25+#if MIN_VERSION_base(4,11,0)
26+import GHC.TypeLits hiding (natVal)
27+#else
23import GHC.TypeLits
28import GHC.TypeLits
29+#endif
24
30
25import Grenade.Core
31import Grenade.Core
26import Grenade.Layers.Internal.Pad
32import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Pooling.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE StandaloneDeriving #-}
4{-# LANGUAGE StandaloneDeriving #-}
@@ -21,7 +22,12 @@ import Data.Maybe
21import Data.Proxy
22import Data.Proxy
22import Data.Serialize
23import Data.Serialize
23import Data.Singletons.TypeLits
24import Data.Singletons.TypeLits
25+
26+#if MIN_VERSION_base(4,11,0)
27+import GHC.TypeLits hiding (natVal)
28+#else
24import GHC.TypeLits
29import GHC.TypeLits
30+#endif
25
31
26import Grenade.Core
32import Grenade.Core
27import Grenade.Layers.Internal.Pooling
33import Grenade.Layers.Internal.Pooling
test/Test/Grenade/Network.hs+30−26
@@ -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
25
25
26−-- import Data.Type.Equality
27−
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 )
32
30
33import Grenade
31import Grenade
34
32
33+#if MIN_VERSION_base(4,11,0)
34+import GHC.TypeLits hiding (natVal)
35+#else
35import GHC.TypeLits
36import GHC.TypeLits
37+#endif
38+
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
101
105
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]
103
107
@@ -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
141
145
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]
143
147
@@ -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
183
187
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]
185
189
@@ -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
220
224
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
247
251
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
281
285
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]
283
287
@@ -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
324
328
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]
326
330
@@ -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
365
369
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
395
399
396 crop_left <- choose 0 10
400 crop_left <- choose 0 10
397 crop_right <- choose 0 10
401 crop_right <- choose 0 10