on master help sign in
Merge pull request #75 from erikd/master

Make it build with ghc 8.4

commit950be38afeb95bc3eb7197b217739b85d30c34ee authorHuw Campbell <huw.campbell@gmail.com> dateWed 19 Sep 2018, 09:46 (8 years ago) parent92b5760f3fbebf
10 files changed+77−37
.travis.yml+2−1 README.md+1−1 grenade.cabal+11−9 src/Grenade/Core/Shape.hs+5 src/Grenade/Layers/Convolution.hs+5 src/Grenade/Layers/Crop.hs+6 src/Grenade/Layers/Deconvolution.hs+5 src/Grenade/Layers/Pad.hs+6 src/Grenade/Layers/Pooling.hs+6 test/Test/Grenade/Network.hs+30−26
.travis.yml+2−1
@@ -4,7 +4,8 @@
44env:
55 - CABALVER=1.22 GHCVER=7.10.3
66 - 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
89
910# Note: the distinction between `before_install` and `install` is not important.
1011before_install:
README.md+1−1
@@ -159,7 +159,7 @@ and the tests run using:
159159./mafia test
160160```
161161
162−Grenade builds with ghc 7.10 and 8.0.
162+Grenade builds with ghc 7.10, 8.0, 8.2 and 8.4.
163163
164164Thanks
165165------
grenade.cabal+11−9
@@ -45,7 +45,9 @@ library
4545 , hmatrix == 0.18.*
4646 , MonadRandom >= 0.4 && < 0.6
4747 , primitive >= 0.6 && < 0.7
48− , singletons >= 2.1 && < 2.4
48+ -- Versions of singletons are *tightly* coupled with the
49+ -- GHC version so its fine to drop version bounds.
50+ , singletons
4951 , vector >= 0.11 && < 0.13
5052
5153 ghc-options:
@@ -146,9 +148,9 @@ test-suite test
146148 ghc-options: -fno-warn-incomplete-patterns
147149
148150 build-depends:
149− base >= 4.8 && < 5
151+ base
150152 , grenade
151− , hedgehog >= 0.5 && < 0.6
153+ , hedgehog >= 0.5 && < 0.7
152154 , hmatrix
153155 , mtl
154156 , singletons
@@ -174,9 +176,9 @@ benchmark bench
174176 bench
175177
176178 build-depends:
177− base >= 3 && < 5
178− , bytestring == 0.10.*
179− , criterion >= 1.1 && < 1.3
179+ base
180+ , bytestring
181+ , criterion >= 1.1 && < 1.5
180182 , grenade
181183 , hmatrix
182184
@@ -191,8 +193,8 @@ benchmark bench-lstm
191193 bench
192194
193195 build-depends:
194− base >= 3 && < 5
195− , bytestring == 0.10.*
196− , criterion == 1.1.*
196+ base
197+ , bytestring
198+ , criterion
197199 , grenade
198200 , hmatrix
src/Grenade/Core/Shape.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE GADTs #-}
34{-# LANGUAGE KindSignatures #-}
@@ -35,7 +36,11 @@ import Data.Singletons.TypeLits
3536import Data.Vector.Storable ( Vector )
3637import qualified Data.Vector.Storable as V
3738
39+#if MIN_VERSION_base(4,11,0)
40+import GHC.TypeLits hiding (natVal)
41+#else
3842import GHC.TypeLits
43+#endif
3944
4045import qualified Numeric.LinearAlgebra.Static as H
4146import Numeric.LinearAlgebra.Static
src/Grenade/Layers/Convolution.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE RecordWildCards #-}
@@ -29,7 +30,11 @@ import Data.Proxy
2930import Data.Serialize
3031import Data.Singletons.TypeLits
3132
33+#if MIN_VERSION_base(4,11,0)
34+import GHC.TypeLits hiding (natVal)
35+#else
3236import GHC.TypeLits
37+#endif
3338
3439import Numeric.LinearAlgebra hiding ( uniformSample, konst )
3540import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Crop.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE GADTs #-}
@@ -20,7 +21,12 @@ import Data.Maybe
2021import Data.Proxy
2122import Data.Serialize
2223import Data.Singletons.TypeLits
24+
25+#if MIN_VERSION_base(4,11,0)
26+import GHC.TypeLits hiding (natVal)
27+#else
2328import GHC.TypeLits
29+#endif
2430
2531import Grenade.Core
2632import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Deconvolution.hs+5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE RecordWildCards #-}
@@ -33,7 +34,11 @@ import Data.Proxy
3334import Data.Serialize
3435import Data.Singletons.TypeLits
3536
37+#if MIN_VERSION_base(4,11,0)
38+import GHC.TypeLits hiding (natVal)
39+#else
3640import GHC.TypeLits
41+#endif
3742
3843import Numeric.LinearAlgebra hiding ( uniformSample, konst )
3944import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Pad.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE GADTs #-}
@@ -20,7 +21,12 @@ import Data.Maybe
2021import Data.Proxy
2122import Data.Serialize
2223import Data.Singletons.TypeLits
24+
25+#if MIN_VERSION_base(4,11,0)
26+import GHC.TypeLits hiding (natVal)
27+#else
2328import GHC.TypeLits
29+#endif
2430
2531import Grenade.Core
2632import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Pooling.hs+6
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DataKinds #-}
23{-# LANGUAGE ScopedTypeVariables #-}
34{-# LANGUAGE StandaloneDeriving #-}
@@ -21,7 +22,12 @@ import Data.Maybe
2122import Data.Proxy
2223import Data.Serialize
2324import Data.Singletons.TypeLits
25+
26+#if MIN_VERSION_base(4,11,0)
27+import GHC.TypeLits hiding (natVal)
28+#else
2429import GHC.TypeLits
30+#endif
2531
2632import Grenade.Core
2733import Grenade.Layers.Internal.Pooling
test/Test/Grenade/Network.hs+30−26
@@ -23,8 +23,6 @@ import Data.Singletons
2323import Data.Singletons.Prelude.List
2424import Data.Singletons.TypeLits
2525
26−-- import Data.Type.Equality
27−
2826import Hedgehog
2927import qualified Hedgehog.Gen as Gen
3028import Hedgehog.Internal.Source
@@ -32,7 +30,12 @@ import Hedgehog.Internal.Property ( failWith )
3230
3331import Grenade
3432
33+#if MIN_VERSION_base(4,11,0)
34+import GHC.TypeLits hiding (natVal)
35+#else
3536import GHC.TypeLits
37+#endif
38+
3639import GHC.TypeLits.Witnesses
3740import Test.Hedgehog.Compat
3841import Test.Hedgehog.TypeLits
@@ -74,8 +77,9 @@ genNetwork =
7477 , pure (SomeNetwork (Elu :~> rest :: Network ( Elu ': layers ) ( h ': h ': hs )))
7578 , pure (SomeNetwork (Softmax :~> rest :: Network ( Softmax ': layers ) ( h ': h ': hs )))
7679 , do -- Reshape to two dimensions
77− let divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
78− let len = natVal l
80+ let divisors :: Integer -> [Integer]
81+ divisors n = 1 : [x | x <- [2..(n-1)], n `rem` x == 0]
82+ let len = fromIntegral $ natVal l
7983 rs <- Gen.element $ divisors len
8084 let cs = len `quot` rs
8185 case ( someNatVal rs, someNatVal cs, someNatVal len ) of
@@ -96,8 +100,8 @@ genNetwork =
96100 , do -- Build a convolution layer with one filter output
97101 -- Figure out some kernel sizes which work for this layer
98102 -- There must be a better way than this...
99− let output_r = natVal r
100− let output_c = natVal c
103+ let output_r = fromIntegral $ natVal r
104+ let output_c = fromIntegral $ natVal c
101105
102106 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
103107
@@ -136,8 +140,8 @@ genNetwork =
136140 , do -- Build a convolution layer with one filter output
137141 -- Figure out some kernel sizes which work for this layer
138142 -- There must be a better way than this...
139− let output_r = natVal r
140− let output_c = natVal c
143+ let output_r = fromIntegral $ natVal r
144+ let output_c = fromIntegral $ natVal c
141145
142146 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
143147
@@ -178,8 +182,8 @@ genNetwork =
178182 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels 1 kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
179183 _ -> Gen.discard -- Can't occur
180184 , do -- Build a Pooling layer
181− let output_r = natVal r
182− let output_c = natVal c
185+ let output_r = fromIntegral $ natVal r
186+ let output_c = fromIntegral $ natVal c
183187
184188 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
185189
@@ -215,8 +219,8 @@ genNetwork =
215219 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D2 inRows inCols) ': h ': hs )))
216220 _ -> Gen.discard -- Can't occur
217221 , do -- Build a Pad layer
218− let output_r = natVal r
219− let output_c = natVal c
222+ let output_r = fromIntegral $ natVal r
223+ let output_c = fromIntegral $ natVal c
220224
221225 pad_left <- choose 0 (output_r - 1)
222226 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -242,8 +246,8 @@ genNetwork =
242246 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D2 inputRows inputColumns) ': h ': hs )))
243247 _ -> Gen.discard -- Can't occur
244248 , do -- Build a Crop layer
245− let output_r = natVal r
246− let output_c = natVal c
249+ let output_r = fromIntegral $ natVal r
250+ let output_c = fromIntegral $ natVal c
247251
248252 crop_left <- choose 0 10
249253 crop_right <- choose 0 10
@@ -275,9 +279,9 @@ genNetwork =
275279 , do -- Build a convolution layer with one filter output
276280 -- Figure out some kernel sizes which work for this layer
277281 -- There must be a better way than this...
278− let output_r = natVal r
279− let output_c = natVal c
280− let output_f = natVal f
282+ let output_r = fromIntegral $ natVal r
283+ let output_c = fromIntegral $ natVal c
284+ let output_f = fromIntegral $ natVal f
281285
282286 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
283287
@@ -318,9 +322,9 @@ genNetwork =
318322 pure (SomeNetwork (conv :~> rest :: Network ( Convolution channels filters kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols channels) ': h ': hs )))
319323 _ -> Gen.discard -- Can't occur
320324 , do -- Build a Pooling layer
321− let output_r = natVal r
322− let output_c = natVal c
323− let output_f = natVal f
325+ let output_r = fromIntegral $ natVal r
326+ let output_c = fromIntegral $ natVal c
327+ let output_f = fromIntegral $ natVal f
324328
325329 let ok extent kernel = [stride | stride <- [ 1 .. extent ], (extent - kernel) `mod` stride == 0]
326330
@@ -359,9 +363,9 @@ genNetwork =
359363 pure (SomeNetwork (Pooling :~> rest :: Network ( Pooling kernelRows kernelCols strideRows strideCols ': layers ) ( ('D3 inRows inCols filters) ': h ': hs )))
360364 _ -> Gen.discard -- Can't occur
361365 , do -- Build a Pad layer
362− let output_r = natVal r
363− let output_c = natVal c
364− let output_f = natVal f
366+ let output_r = fromIntegral $ natVal r
367+ let output_c = fromIntegral $ natVal c
368+ let output_f = fromIntegral $ natVal f
365369
366370 pad_left <- choose 0 (output_r - 1)
367371 pad_right <- choose 0 (output_r - 1 - pad_left)
@@ -389,9 +393,9 @@ genNetwork =
389393 pure (SomeNetwork (Pad :~> rest :: Network ( Pad padLeft padTop padRight padBottom ': layers ) ( ('D3 inputRows inputColumns filters) ': h ': hs )))
390394 _ -> Gen.discard -- Can't occur
391395 , do -- Build a Crop layer
392− let output_r = natVal r
393− let output_c = natVal c
394− let output_f = natVal f
396+ let output_r = fromIntegral $ natVal r
397+ let output_c = fromIntegral $ natVal c
398+ let output_f = fromIntegral $ natVal f
395399
396400 crop_left <- choose 0 10
397401 crop_right <- choose 0 10