on b79918b help sign in
20 files changed+102−46
since splitsnapshots
unifiedsplit
examples/grenade-examples.cabal+5−6 examples/main/shakespeare.hs+7−2 grenade.cabal+1−2 src/Grenade/Core/Network.hs+1−1 src/Grenade/Core/Runner.hs+1−2 src/Grenade/Core/Shape.hs+31−16 src/Grenade/Layers/Convolution.hs+7 src/Grenade/Layers/Crop.hs+7 src/Grenade/Layers/Deconvolution.hs+7 src/Grenade/Layers/FullyConnected.hs+1−1 src/Grenade/Layers/Pad.hs+7 src/Grenade/Layers/Pooling.hs+7 src/Grenade/Layers/Reshape.hs+1 src/Grenade/Recurrent/Core/Network.hs+4−1 src/Grenade/Recurrent/Core/Runner.hs+1−1 src/Grenade/Recurrent/Layers/BasicRecurrent.hs+3 src/Grenade/Recurrent/Layers/LSTM.hs+4−1 src/Grenade/Utils/OneHot.hs+1−1 stack.yaml+1−7 stack.yaml.lock+5−5
examples/grenade-examples.cabal+5−6
@@ -26,7 +26,7 @@ executable feedforward
2626 , bytestring
2727 , cereal
2828 , either
29− , optparse-applicative >= 0.13 && < 0.18
29+ , optparse-applicative >= 0.13 && < 0.17
3030 , text == 1.2.*
3131 , mtl >= 2.2.1 && < 2.3
3232 , hmatrix
@@ -42,7 +42,7 @@ executable mnist
4242 , grenade
4343 , attoparsec
4444 , either
45− , optparse-applicative >= 0.13 && < 0.18
45+ , optparse-applicative >= 0.13 && < 0.17
4646 , text == 1.2.*
4747 , mtl >= 2.2.1 && < 2.3
4848 , hmatrix >= 0.18 && < 0.21
@@ -61,7 +61,7 @@ executable gan-mnist
6161 , bytestring
6262 , cereal
6363 , either
64− , optparse-applicative >= 0.13 && < 0.18
64+ , optparse-applicative >= 0.13 && < 0.17
6565 , text == 1.2.*
6666 , mtl >= 2.2.1 && < 2.3
6767 , hmatrix >= 0.18 && < 0.21
@@ -78,7 +78,7 @@ executable recurrent
7878 , grenade
7979 , attoparsec
8080 , either
81− , optparse-applicative >= 0.13 && < 0.18
81+ , optparse-applicative >= 0.13 && < 0.17
8282 , text == 1.2.*
8383 , mtl >= 2.2.1 && < 2.3
8484 , hmatrix >= 0.18 && < 0.21
@@ -96,14 +96,13 @@ executable shakespeare
9696 , bytestring
9797 , cereal
9898 , either
99− , optparse-applicative >= 0.13 && < 0.18
99+ , optparse-applicative >= 0.13 && < 0.17
100100 , text == 1.2.*
101101 , mtl >= 2.2.1 && < 2.3
102102 , hmatrix >= 0.18 && < 0.21
103103 , transformers
104104 , semigroups
105105 , singletons
106− , singletons-base
107106 , vector
108107 , MonadRandom
109108 , containers
examples/main/shakespeare.hs+7−2
@@ -14,15 +14,22 @@ import Data.Char ( isUpper, toUpper, toLower )
1414import Data.List ( foldl' )
1515import Data.Maybe ( fromMaybe )
1616
17+#if ! MIN_VERSION_base(4,13,0)
18+import Data.Semigroup ( (<>) )
19+#endif
1720
1821import qualified Data.Vector as V
1922import Data.Vector ( Vector )
2023
2124import qualified Data.Map as M
25+#if ! MIN_VERSION_base(4,13,0)
26+import Data.Proxy ( Proxy (..) )
27+#endif
2228
2329import qualified Data.ByteString as B
2430import Data.Serialize
2531
32+import Data.Singletons.Prelude
2633import GHC.TypeLits
2734
2835import Numeric.LinearAlgebra.Static ( konst )
@@ -34,8 +41,6 @@ import Grenade.Recurrent
3441import Grenade.Utils.OneHot
3542
3643import System.IO.Unsafe ( unsafeInterleaveIO )
37−import Data.Proxy
38−import Prelude.Singletons
3944
4045-- The defininition for our natural language recurrent network.
4146-- This network is able to learn and generate simple words in
grenade.cabal+1−2
@@ -38,7 +38,7 @@ source-repository head
3838library
3939 build-depends:
4040 base >= 4.8 && < 5
41− , bytestring >= 0.10.0
41+ , bytestring == 0.10.*
4242 , containers >= 0.5 && < 0.7
4343 , cereal >= 0.5 && < 0.6
4444 , deepseq >= 1.4 && < 1.5
@@ -48,7 +48,6 @@ library
4848 -- Versions of singletons are *tightly* coupled with the
4949 -- GHC version so its fine to drop version bounds.
5050 , singletons
51− , singletons-base
5251 , vector >= 0.11 && < 0.13
5352
5453 ghc-options:
src/Grenade/Core/Network.hs+1−1
@@ -34,6 +34,7 @@ module Grenade.Core.Network (
3434import Control.Monad.Random ( MonadRandom )
3535
3636import Data.Singletons
37+import Data.Singletons.Prelude
3738import Data.Serialize
3839
3940#if MIN_VERSION_base(4,9,0)
@@ -43,7 +44,6 @@ import Data.Kind (Type)
4344import Grenade.Core.Layer
4445import Grenade.Core.LearningParameters
4546import Grenade.Core.Shape
46−import Prelude.Singletons
4747
4848-- | Type of a network.
4949--
src/Grenade/Core/Runner.hs+1−2
@@ -13,12 +13,11 @@ module Grenade.Core.Runner (
1313 , runNet
1414 ) where
1515
16+import Data.Singletons.Prelude
1617
1718import Grenade.Core.LearningParameters
1819import Grenade.Core.Network
1920import Grenade.Core.Shape
20−import Data.Singletons
21−import Prelude.Singletons
2221
2322-- | Perform reverse automatic differentiation on the network
2423-- for the current input and expected output.
src/Grenade/Core/Shape.hs+31−16
@@ -21,20 +21,35 @@ Stability : experimental
2121module Grenade.Core.Shape (
2222 S (..)
2323 , Shape (..)
24+#if MIN_VERSION_singletons(2,6,0)
2425 , SShape (..)
26+#else
27+ , Sing (..)
28+#endif
29+
2530 , randomOfShape
2631 , fromStorable
2732 ) where
2833
2934import Control.DeepSeq (NFData (..))
3035import Control.Monad.Random ( MonadRandom, getRandom )
36+
37+#if MIN_VERSION_base(4,13,0)
3138import Data.Kind (Type)
39+#endif
3240import Data.Proxy
3341import Data.Serialize
3442import Data.Singletons
43+import Data.Singletons.TypeLits
3544import Data.Vector.Storable ( Vector )
3645import qualified Data.Vector.Storable as V
46+
47+#if MIN_VERSION_base(4,11,0)
48+import GHC.TypeLits hiding (natVal)
49+#else
3750import GHC.TypeLits
51+#endif
52+
3853import qualified Numeric.LinearAlgebra.Static as H
3954import Numeric.LinearAlgebra.Static
4055import qualified Numeric.LinearAlgebra as NLA
@@ -84,9 +99,9 @@ deriving instance Show (S n)
8499type instance Sing = SShape
85100
86101data SShape :: Shape -> Type where
87− D1Sing :: KnownNat a => SShape ('D1 a)
88− D2Sing :: (KnownNat a, KnownNat b) => SShape ('D2 a b)
89− D3Sing :: (KnownNat (a * c), KnownNat a, KnownNat b, KnownNat c) => SShape ('D3 a b c)
102+ D1Sing :: Sing a -> SShape ('D1 a)
103+ D2Sing :: Sing a -> Sing b -> SShape ('D2 a b)
104+ D3Sing :: KnownNat (a * c) => Sing a -> Sing b -> Sing c -> SShape ('D3 a b c)
90105#else
91106data instance Sing (n :: Shape) where
92107 D1Sing :: Sing a -> Sing ('D1 a)
@@ -95,11 +110,11 @@ data instance Sing (n :: Shape) where
95110#endif
96111
97112instance KnownNat a => SingI ('D1 a) where
98− sing = D1Sing
113+ sing = D1Sing sing
99114instance (KnownNat a, KnownNat b) => SingI ('D2 a b) where
100− sing = D2Sing
115+ sing = D2Sing sing sing
101116instance (KnownNat a, KnownNat b, KnownNat c, KnownNat (a * c)) => SingI ('D3 a b c) where
102− sing = D3Sing
117+ sing = D3Sing sing sing sing
103118
104119instance SingI x => Num (S x) where
105120 (+) = n2 (+)
@@ -148,13 +163,13 @@ randomOfShape :: forall x m. ( MonadRandom m, SingI x ) => m (S x)
148163randomOfShape = do
149164 seed :: Int <- getRandom
150165 return $ case (sing :: Sing x) of
151− D1Sing ->
166+ D1Sing SNat ->
152167 S1D (randomVector seed Uniform * 2 - 1)
153168
154− D2Sing ->
169+ D2Sing SNat SNat ->
155170 S2D (uniformSample seed (-1) 1)
156171
157− D3Sing ->
172+ D3Sing SNat SNat SNat ->
158173 S3D (uniformSample seed (-1) 1)
159174
160175-- | Generate a shape from a Storable Vector.
@@ -162,13 +177,13 @@ randomOfShape = do
162177-- Returns Nothing if the vector is of the wrong size.
163178fromStorable :: forall x. SingI x => Vector Double -> Maybe (S x)
164179fromStorable xs = case sing :: Sing x of
165− D1Sing ->
180+ D1Sing SNat ->
166181 S1D <$> H.create xs
167182
168− D2Sing ->
183+ D2Sing SNat SNat ->
169184 S2D <$> mkL xs
170185
171− D3Sing ->
186+ D3Sing SNat SNat SNat ->
172187 S3D <$> mkL xs
173188 where
174189 mkL :: forall rows columns. (KnownNat rows, KnownNat columns)
@@ -205,13 +220,13 @@ n2 f (S2D x) (S2D y) = S2D (f x y)
205220n2 f (S3D x) (S3D y) = S3D (f x y)
206221
207222-- Helper function for creating the number instances
208−nk :: forall x. (SingI x) => Double -> S x
223+nk :: forall x. SingI x => Double -> S x
209224nk x = case (sing :: Sing x) of
210− D1Sing ->
225+ D1Sing SNat ->
211226 S1D (konst x)
212227
213− D2Sing ->
228+ D2Sing SNat SNat ->
214229 S2D (konst x)
215230
216− D3Sing ->
231+ D3Sing SNat SNat SNat ->
217232 S3D (konst x)
src/Grenade/Layers/Convolution.hs+7
@@ -28,9 +28,16 @@ import Control.Monad.Random hiding ( fromList )
2828import Data.Maybe
2929import Data.Proxy
3030import Data.Serialize
31+import 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
38+#if MIN_VERSION_base(4,9,0)
3339import Data.Kind (Type)
40+#endif
3441
3542import Numeric.LinearAlgebra hiding ( uniformSample, konst )
3643import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Crop.hs+7
@@ -21,9 +21,16 @@ module Grenade.Layers.Crop (
2121import Data.Maybe
2222import Data.Proxy
2323import Data.Serialize
24+import Data.Singletons.TypeLits
2425
26+#if MIN_VERSION_base(4,11,0)
27+import GHC.TypeLits hiding (natVal)
28+#else
2529import GHC.TypeLits
30+#endif
31+#if MIN_VERSION_base(4,9,0)
2632import Data.Kind (Type)
33+#endif
2734
2835import Grenade.Core
2936import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Deconvolution.hs+7
@@ -32,9 +32,16 @@ import Control.Monad.Random hiding ( fromList )
3232import Data.Maybe
3333import Data.Proxy
3434import Data.Serialize
35+import 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
42+#if MIN_VERSION_base(4,9,0)
3743import Data.Kind (Type)
44+#endif
3845
3946import Numeric.LinearAlgebra hiding ( uniformSample, konst )
4047import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/FullyConnected.hs+1−1
@@ -13,6 +13,7 @@ import Control.Monad.Random hiding (fromList)
1313
1414import Data.Proxy
1515import Data.Serialize
16+import Data.Singletons.TypeLits
1617
1718import qualified Numeric.LinearAlgebra as LA
1819import Numeric.LinearAlgebra.Static
@@ -20,7 +21,6 @@ import Numeric.LinearAlgebra.Static
2021import Grenade.Core
2122
2223import Grenade.Layers.Internal.Update
23−import GHC.TypeLits
2424
2525-- | A basic fully connected (or inner product) neural network layer.
2626data FullyConnected i o = FullyConnected
src/Grenade/Layers/Pad.hs+7
@@ -21,9 +21,16 @@ module Grenade.Layers.Pad (
2121import Data.Maybe
2222import Data.Proxy
2323import Data.Serialize
24+import Data.Singletons.TypeLits
2425
26+#if MIN_VERSION_base(4,11,0)
27+import GHC.TypeLits hiding (natVal)
28+#else
2529import GHC.TypeLits
30+#endif
31+#if MIN_VERSION_base(4,9,0)
2632import Data.Kind (Type)
33+#endif
2734
2835import Grenade.Core
2936import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Pooling.hs+7
@@ -22,9 +22,16 @@ module Grenade.Layers.Pooling (
2222import Data.Maybe
2323import Data.Proxy
2424import Data.Serialize
25+import Data.Singletons.TypeLits
2526
27+#if MIN_VERSION_base(4,11,0)
28+import GHC.TypeLits hiding (natVal)
29+#else
2630import GHC.TypeLits
31+#endif
32+#if MIN_VERSION_base(4,9,0)
2733import Data.Kind (Type)
34+#endif
2835
2936import Grenade.Core
3037import Grenade.Layers.Internal.Pooling
src/Grenade/Layers/Reshape.hs+1
@@ -17,6 +17,7 @@ module Grenade.Layers.Reshape (
1717
1818import Data.Serialize
1919
20+import Data.Singletons.TypeLits
2021import GHC.TypeLits
2122
2223import Numeric.LinearAlgebra.Static
src/Grenade/Recurrent/Core/Network.hs+4−1
@@ -29,13 +29,16 @@ module Grenade.Recurrent.Core.Network (
2929
3030
3131import Control.Monad.Random ( MonadRandom )
32+import Data.Singletons ( SingI )
33+import Data.Singletons.Prelude ( Head, Last )
3234import Data.Serialize
3335
36+#if MIN_VERSION_base(4,9,0)
3437import Data.Kind (Type)
38+#endif
3539
3640import Grenade.Core
3741import Grenade.Recurrent.Core.Layer
38−import Prelude.Singletons
3942
4043-- | Witness type to say indicate we're building up with a normal feed
4144-- forward layer.
src/Grenade/Recurrent/Core/Runner.hs+1−1
@@ -17,10 +17,10 @@ module Grenade.Recurrent.Core.Runner (
1717 ) where
1818
1919import Data.List ( foldl' )
20+import Data.Singletons.Prelude
2021import Grenade.Core
2122
2223import Grenade.Recurrent.Core.Network
23−import Prelude.Singletons
2424
2525type RecurrentGradients layers = [RecurrentGradient layers]
2626
src/Grenade/Recurrent/Layers/BasicRecurrent.hs+3
@@ -16,8 +16,11 @@ module Grenade.Recurrent.Layers.BasicRecurrent (
1616
1717import Control.Monad.Random ( MonadRandom, getRandom )
1818
19+import Data.Singletons.TypeLits
1920
21+#if MIN_VERSION_base(4,9,0)
2022import Data.Kind (Type)
23+#endif
2124
2225import Numeric.LinearAlgebra.Static
2326
src/Grenade/Recurrent/Layers/LSTM.hs+4−1
@@ -21,7 +21,11 @@ import Control.Monad.Random ( MonadRandom, getRandom )
2121-- import Data.List ( foldl1' )
2222import Data.Proxy
2323import Data.Serialize
24+import Data.Singletons.TypeLits
25+
26+#if MIN_VERSION_base(4,9,0)
2427import Data.Kind (Type)
28+#endif
2529
2630import qualified Numeric.LinearAlgebra as LA
2731import Numeric.LinearAlgebra.Static
@@ -29,7 +33,6 @@ import Numeric.LinearAlgebra.Static
2933import Grenade.Core
3034import Grenade.Recurrent.Core
3135import Grenade.Layers.Internal.Update
32−import GHC.TypeLits
3336
3437
3538-- | Long Short Term Memory Recurrent unit
src/Grenade/Utils/OneHot.hs+1−1
@@ -22,6 +22,7 @@ import Data.Map ( Map )
2222import qualified Data.Map as M
2323
2424import Data.Proxy
25+import Data.Singletons.TypeLits
2526
2627import Data.Vector ( Vector )
2728import qualified Data.Vector as V
@@ -30,7 +31,6 @@ import qualified Data.Vector.Storable as VS
3031import Numeric.LinearAlgebra ( maxIndex )
3132import Numeric.LinearAlgebra.Devel
3233import Numeric.LinearAlgebra.Static
33−import GHC.TypeLits
3434
3535import Grenade.Core.Shape
3636
stack.yaml+1−7
@@ -20,7 +20,7 @@
2020#
2121# resolver: ./custom-snapshot.yaml
2222# resolver: https://example.com/snapshots/2018-01-01.yaml
23−resolver: lts-20.18
23+resolver: lts-18.28
2424
2525# User packages to be built.
2626# Various formats can be used as shown in the example below.
@@ -70,9 +70,3 @@ extra-deps:
7070#
7171# Allow a newer minor version of GHC than the snapshot specifies
7272# compiler-check: newer-minor
73−
74−nix:
75− enable: true
76− packages:
77− - blas
78− - lapack
stack.yaml.lock+5−5
@@ -7,13 +7,13 @@ packages:
77- completed:
88 hackage: typelits-witnesses-0.3.0.3@sha256:2d9df4ac6ff3077bfd2bf659e4b495e157723ac5b45c519762853f55df5c16db,2738
99 pantry-tree:
10− sha256: 6a42a462f98e94933b6e9721acd912c6c6b6a4743635efd15cc5871908c816a0
1110 size: 469
11+ sha256: 6a42a462f98e94933b6e9721acd912c6c6b6a4743635efd15cc5871908c816a0
1212 original:
1313 hackage: typelits-witnesses-0.3.0.3
1414snapshots:
1515- completed:
16− sha256: 9fa4bece7acfac1fc7930c5d6e24606004b09e80aa0e52e9f68b148201008db9
17− size: 649606
18− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/18.yaml
19− original: lts-20.18
16+ size: 590100
17+ url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
18+ sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68
19+ original: lts-18.28