on master help sign in
20 files changed+46−102
since splitsnapshots
unifiedsplit
examples/grenade-examples.cabal+6−5 examples/main/shakespeare.hs+2−7 grenade.cabal+2−1 src/Grenade/Core/Network.hs+1−1 src/Grenade/Core/Runner.hs+2−1 src/Grenade/Core/Shape.hs+16−31 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+1−4 src/Grenade/Recurrent/Core/Runner.hs+1−1 src/Grenade/Recurrent/Layers/BasicRecurrent.hs−3 src/Grenade/Recurrent/Layers/LSTM.hs+1−4 src/Grenade/Utils/OneHot.hs+1−1 stack.yaml+7−1 stack.yaml.lock+5−5
examples/grenade-examples.cabal+6−5
@@ -26,7 +26,7 @@ executable feedforward
2626 , bytestring
2727 , cereal
2828 , either
29− , optparse-applicative >= 0.13 && < 0.16
29+ , optparse-applicative >= 0.13 && < 0.18
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.16
45+ , optparse-applicative >= 0.13 && < 0.18
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.16
64+ , optparse-applicative >= 0.13 && < 0.18
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.16
81+ , optparse-applicative >= 0.13 && < 0.18
8282 , text == 1.2.*
8383 , mtl >= 2.2.1 && < 2.3
8484 , hmatrix >= 0.18 && < 0.21
@@ -96,13 +96,14 @@ executable shakespeare
9696 , bytestring
9797 , cereal
9898 , either
99− , optparse-applicative >= 0.13 && < 0.16
99+ , optparse-applicative >= 0.13 && < 0.18
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
106107 , vector
107108 , MonadRandom
108109 , containers
examples/main/shakespeare.hs+2−7
@@ -14,22 +14,15 @@ 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
2017
2118import qualified Data.Vector as V
2219import Data.Vector ( Vector )
2320
2421import qualified Data.Map as M
25−#if ! MIN_VERSION_base(4,13,0)
26−import Data.Proxy ( Proxy (..) )
27−#endif
2822
2923import qualified Data.ByteString as B
3024import Data.Serialize
3125
32−import Data.Singletons.Prelude
3326import GHC.TypeLits
3427
3528import Numeric.LinearAlgebra.Static ( konst )
@@ -41,6 +34,8 @@ import Grenade.Recurrent
4134import Grenade.Utils.OneHot
4235
4336import System.IO.Unsafe ( unsafeInterleaveIO )
37+import Data.Proxy
38+import Prelude.Singletons
4439
4540-- The defininition for our natural language recurrent network.
4641-- This network is able to learn and generate simple words in
grenade.cabal+2−1
@@ -38,7 +38,7 @@ source-repository head
3838library
3939 build-depends:
4040 base >= 4.8 && < 5
41− , bytestring == 0.10.*
41+ , bytestring >= 0.10.0
4242 , containers >= 0.5 && < 0.7
4343 , cereal >= 0.5 && < 0.6
4444 , deepseq >= 1.4 && < 1.5
@@ -48,6 +48,7 @@ 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
5152 , vector >= 0.11 && < 0.13
5253
5354 ghc-options:
src/Grenade/Core/Network.hs+1−1
@@ -34,7 +34,6 @@ module Grenade.Core.Network (
3434import Control.Monad.Random ( MonadRandom )
3535
3636import Data.Singletons
37−import Data.Singletons.Prelude
3837import Data.Serialize
3938
4039#if MIN_VERSION_base(4,9,0)
@@ -44,6 +43,7 @@ import Data.Kind (Type)
4443import Grenade.Core.Layer
4544import Grenade.Core.LearningParameters
4645import Grenade.Core.Shape
46+import Prelude.Singletons
4747
4848-- | Type of a network.
4949--
src/Grenade/Core/Runner.hs+2−1
@@ -13,11 +13,12 @@ module Grenade.Core.Runner (
1313 , runNet
1414 ) where
1515
16−import Data.Singletons.Prelude
1716
1817import Grenade.Core.LearningParameters
1918import Grenade.Core.Network
2019import Grenade.Core.Shape
20+import Data.Singletons
21+import Prelude.Singletons
2122
2223-- | Perform reverse automatic differentiation on the network
2324-- for the current input and expected output.
src/Grenade/Core/Shape.hs+16−31
@@ -21,35 +21,20 @@ Stability : experimental
2121module Grenade.Core.Shape (
2222 S (..)
2323 , Shape (..)
24−#if MIN_VERSION_singletons(2,6,0)
2524 , SShape (..)
26−#else
27− , Sing (..)
28−#endif
29−
3025 , randomOfShape
3126 , fromStorable
3227 ) where
3328
3429import Control.DeepSeq (NFData (..))
3530import Control.Monad.Random ( MonadRandom, getRandom )
36−
37−#if MIN_VERSION_base(4,13,0)
3831import Data.Kind (Type)
39−#endif
4032import Data.Proxy
4133import Data.Serialize
4234import Data.Singletons
43−import Data.Singletons.TypeLits
4435import Data.Vector.Storable ( Vector )
4536import qualified Data.Vector.Storable as V
46−
47−#if MIN_VERSION_base(4,11,0)
48−import GHC.TypeLits hiding (natVal)
49−#else
5037import GHC.TypeLits
51−#endif
52−
5338import qualified Numeric.LinearAlgebra.Static as H
5439import Numeric.LinearAlgebra.Static
5540import qualified Numeric.LinearAlgebra as NLA
@@ -99,9 +84,9 @@ deriving instance Show (S n)
9984type instance Sing = SShape
10085
10186data SShape :: Shape -> Type where
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)
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)
10590#else
10691data instance Sing (n :: Shape) where
10792 D1Sing :: Sing a -> Sing ('D1 a)
@@ -110,11 +95,11 @@ data instance Sing (n :: Shape) where
11095#endif
11196
11297instance KnownNat a => SingI ('D1 a) where
113− sing = D1Sing sing
98+ sing = D1Sing
11499instance (KnownNat a, KnownNat b) => SingI ('D2 a b) where
115− sing = D2Sing sing sing
100+ sing = D2Sing
116101instance (KnownNat a, KnownNat b, KnownNat c, KnownNat (a * c)) => SingI ('D3 a b c) where
117− sing = D3Sing sing sing sing
102+ sing = D3Sing
118103
119104instance SingI x => Num (S x) where
120105 (+) = n2 (+)
@@ -163,13 +148,13 @@ randomOfShape :: forall x m. ( MonadRandom m, SingI x ) => m (S x)
163148randomOfShape = do
164149 seed :: Int <- getRandom
165150 return $ case (sing :: Sing x) of
166− D1Sing SNat ->
151+ D1Sing ->
167152 S1D (randomVector seed Uniform * 2 - 1)
168153
169− D2Sing SNat SNat ->
154+ D2Sing ->
170155 S2D (uniformSample seed (-1) 1)
171156
172− D3Sing SNat SNat SNat ->
157+ D3Sing ->
173158 S3D (uniformSample seed (-1) 1)
174159
175160-- | Generate a shape from a Storable Vector.
@@ -177,13 +162,13 @@ randomOfShape = do
177162-- Returns Nothing if the vector is of the wrong size.
178163fromStorable :: forall x. SingI x => Vector Double -> Maybe (S x)
179164fromStorable xs = case sing :: Sing x of
180− D1Sing SNat ->
165+ D1Sing ->
181166 S1D <$> H.create xs
182167
183− D2Sing SNat SNat ->
168+ D2Sing ->
184169 S2D <$> mkL xs
185170
186− D3Sing SNat SNat SNat ->
171+ D3Sing ->
187172 S3D <$> mkL xs
188173 where
189174 mkL :: forall rows columns. (KnownNat rows, KnownNat columns)
@@ -220,13 +205,13 @@ n2 f (S2D x) (S2D y) = S2D (f x y)
220205n2 f (S3D x) (S3D y) = S3D (f x y)
221206
222207-- Helper function for creating the number instances
223−nk :: forall x. SingI x => Double -> S x
208+nk :: forall x. (SingI x) => Double -> S x
224209nk x = case (sing :: Sing x) of
225− D1Sing SNat ->
210+ D1Sing ->
226211 S1D (konst x)
227212
228− D2Sing SNat SNat ->
213+ D2Sing ->
229214 S2D (konst x)
230215
231− D3Sing SNat SNat SNat ->
216+ D3Sing ->
232217 S3D (konst x)
src/Grenade/Layers/Convolution.hs−7
@@ -28,16 +28,9 @@ import Control.Monad.Random hiding ( fromList )
2828import Data.Maybe
2929import Data.Proxy
3030import Data.Serialize
31−import Data.Singletons.TypeLits
3231
33−#if MIN_VERSION_base(4,11,0)
34−import GHC.TypeLits hiding (natVal)
35−#else
3632import GHC.TypeLits
37−#endif
38−#if MIN_VERSION_base(4,9,0)
3933import Data.Kind (Type)
40−#endif
4134
4235import Numeric.LinearAlgebra hiding ( uniformSample, konst )
4336import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/Crop.hs−7
@@ -21,16 +21,9 @@ module Grenade.Layers.Crop (
2121import Data.Maybe
2222import Data.Proxy
2323import Data.Serialize
24−import Data.Singletons.TypeLits
2524
26−#if MIN_VERSION_base(4,11,0)
27−import GHC.TypeLits hiding (natVal)
28−#else
2925import GHC.TypeLits
30−#endif
31−#if MIN_VERSION_base(4,9,0)
3226import Data.Kind (Type)
33−#endif
3427
3528import Grenade.Core
3629import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Deconvolution.hs−7
@@ -32,16 +32,9 @@ import Control.Monad.Random hiding ( fromList )
3232import Data.Maybe
3333import Data.Proxy
3434import Data.Serialize
35−import Data.Singletons.TypeLits
3635
37−#if MIN_VERSION_base(4,11,0)
38−import GHC.TypeLits hiding (natVal)
39−#else
4036import GHC.TypeLits
41−#endif
42−#if MIN_VERSION_base(4,9,0)
4337import Data.Kind (Type)
44−#endif
4538
4639import Numeric.LinearAlgebra hiding ( uniformSample, konst )
4740import qualified Numeric.LinearAlgebra as LA
src/Grenade/Layers/FullyConnected.hs+1−1
@@ -13,7 +13,6 @@ import Control.Monad.Random hiding (fromList)
1313
1414import Data.Proxy
1515import Data.Serialize
16−import Data.Singletons.TypeLits
1716
1817import qualified Numeric.LinearAlgebra as LA
1918import Numeric.LinearAlgebra.Static
@@ -21,6 +20,7 @@ import Numeric.LinearAlgebra.Static
2120import Grenade.Core
2221
2322import 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,16 +21,9 @@ module Grenade.Layers.Pad (
2121import Data.Maybe
2222import Data.Proxy
2323import Data.Serialize
24−import Data.Singletons.TypeLits
2524
26−#if MIN_VERSION_base(4,11,0)
27−import GHC.TypeLits hiding (natVal)
28−#else
2925import GHC.TypeLits
30−#endif
31−#if MIN_VERSION_base(4,9,0)
3226import Data.Kind (Type)
33−#endif
3427
3528import Grenade.Core
3629import Grenade.Layers.Internal.Pad
src/Grenade/Layers/Pooling.hs−7
@@ -22,16 +22,9 @@ module Grenade.Layers.Pooling (
2222import Data.Maybe
2323import Data.Proxy
2424import Data.Serialize
25−import Data.Singletons.TypeLits
2625
27−#if MIN_VERSION_base(4,11,0)
28−import GHC.TypeLits hiding (natVal)
29−#else
3026import GHC.TypeLits
31−#endif
32−#if MIN_VERSION_base(4,9,0)
3327import Data.Kind (Type)
34−#endif
3528
3629import Grenade.Core
3730import Grenade.Layers.Internal.Pooling
src/Grenade/Layers/Reshape.hs−1
@@ -17,7 +17,6 @@ module Grenade.Layers.Reshape (
1717
1818import Data.Serialize
1919
20−import Data.Singletons.TypeLits
2120import GHC.TypeLits
2221
2322import Numeric.LinearAlgebra.Static
src/Grenade/Recurrent/Core/Network.hs+1−4
@@ -29,16 +29,13 @@ module Grenade.Recurrent.Core.Network (
2929
3030
3131import Control.Monad.Random ( MonadRandom )
32−import Data.Singletons ( SingI )
33−import Data.Singletons.Prelude ( Head, Last )
3432import Data.Serialize
3533
36−#if MIN_VERSION_base(4,9,0)
3734import Data.Kind (Type)
38−#endif
3935
4036import Grenade.Core
4137import Grenade.Recurrent.Core.Layer
38+import Prelude.Singletons
4239
4340-- | Witness type to say indicate we're building up with a normal feed
4441-- 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
2120import Grenade.Core
2221
2322import Grenade.Recurrent.Core.Network
23+import Prelude.Singletons
2424
2525type RecurrentGradients layers = [RecurrentGradient layers]
2626
src/Grenade/Recurrent/Layers/BasicRecurrent.hs−3
@@ -16,11 +16,8 @@ module Grenade.Recurrent.Layers.BasicRecurrent (
1616
1717import Control.Monad.Random ( MonadRandom, getRandom )
1818
19−import Data.Singletons.TypeLits
2019
21−#if MIN_VERSION_base(4,9,0)
2220import Data.Kind (Type)
23−#endif
2421
2522import Numeric.LinearAlgebra.Static
2623
src/Grenade/Recurrent/Layers/LSTM.hs+1−4
@@ -21,11 +21,7 @@ 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)
2724import Data.Kind (Type)
28−#endif
2925
3026import qualified Numeric.LinearAlgebra as LA
3127import Numeric.LinearAlgebra.Static
@@ -33,6 +29,7 @@ import Numeric.LinearAlgebra.Static
3329import Grenade.Core
3430import Grenade.Recurrent.Core
3531import Grenade.Layers.Internal.Update
32+import GHC.TypeLits
3633
3734
3835-- | Long Short Term Memory Recurrent unit
src/Grenade/Utils/OneHot.hs+1−1
@@ -22,7 +22,6 @@ import Data.Map ( Map )
2222import qualified Data.Map as M
2323
2424import Data.Proxy
25−import Data.Singletons.TypeLits
2625
2726import Data.Vector ( Vector )
2827import qualified Data.Vector as V
@@ -31,6 +30,7 @@ import qualified Data.Vector.Storable as VS
3130import Numeric.LinearAlgebra ( maxIndex )
3231import Numeric.LinearAlgebra.Devel
3332import Numeric.LinearAlgebra.Static
33+import GHC.TypeLits
3434
3535import Grenade.Core.Shape
3636
stack.yaml+7−1
@@ -20,7 +20,7 @@
2020#
2121# resolver: ./custom-snapshot.yaml
2222# resolver: https://example.com/snapshots/2018-01-01.yaml
23−resolver: lts-15.5
23+resolver: lts-20.18
2424
2525# User packages to be built.
2626# Various formats can be used as shown in the example below.
@@ -70,3 +70,9 @@ 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− size: 469
1110 sha256: 6a42a462f98e94933b6e9721acd912c6c6b6a4743635efd15cc5871908c816a0
11+ size: 469
1212 original:
1313 hackage: typelits-witnesses-0.3.0.3
1414snapshots:
1515- completed:
16− size: 491372
17− url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/5.yaml
18− sha256: 1b549cfff328040c382a70a84a2087aac8dab6d778bf92f32a93a771a1980dfc
19− original: lts-15.5
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