backprop 0.1.5.0 → 0.1.5.1
raw patch · 4 files changed
+76/−12 lines, 4 filesdep +binaryPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: binary
API changes (from Hackage documentation)
+ Numeric.Backprop.Tuple: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (Numeric.Backprop.Tuple.T2 a b)
+ Numeric.Backprop.Tuple: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b, Data.Binary.Class.Binary c) => Data.Binary.Class.Binary (Numeric.Backprop.Tuple.T3 a b c)
+ Numeric.Backprop.Tuple: instance (Type.Class.Known.Known [*] (Data.Type.Length.Length *) as, Type.Family.List.ListC ((Type.Family.List.<$>) * GHC.Types.Constraint Data.Binary.Class.Binary as)) => Data.Binary.Class.Binary (Numeric.Backprop.Tuple.T as)
+ Numeric.Backprop.Tuple: instance (Type.Family.List.ListC ((Type.Family.List.<$>) * GHC.Types.Constraint GHC.Classes.Eq as), Type.Family.List.ListC ((Type.Family.List.<$>) * GHC.Types.Constraint GHC.Classes.Ord as)) => GHC.Classes.Ord (Numeric.Backprop.Tuple.T as)
+ Numeric.Backprop.Tuple: instance Data.Binary.Class.Binary Numeric.Backprop.Tuple.T0
+ Numeric.Backprop.Tuple: instance Type.Family.List.ListC ((Type.Family.List.<$>) * GHC.Types.Constraint GHC.Classes.Eq as) => GHC.Classes.Eq (Numeric.Backprop.Tuple.T as)
+ Numeric.Backprop.Tuple: instance Type.Family.List.ListC ((Type.Family.List.<$>) * GHC.Types.Constraint GHC.Show.Show as) => GHC.Show.Show (Numeric.Backprop.Tuple.T as)
Files
- CHANGELOG.md +15/−0
- backprop.cabal +4/−3
- src/Numeric/Backprop/Internal.hs +6/−0
- src/Numeric/Backprop/Tuple.hs +51/−9
CHANGELOG.md view
@@ -1,6 +1,21 @@ Changelog ========= +Version 0.1.5.1+---------------++*Apr 8, 2018*++<https://github.com/mstksg/backprop/releases/tag/v0.1.5.1>++* Fixed `NFData` instance for `T`; before, was shallow.+* Added `Typeable` instances for all tuple types, and for `BVar`.+* Added `Eq`, `Ord`, `Show`, etc. instances for `T`.+* Added `Binary` instances for all tuple types. Note that this does incur a+ *binary* dependency only because of the tuple types; however, this will+ hopefully be not too much of an issue because *binary* is a GHC library+ anyway.+ Version 0.1.5.0 ---------------
backprop.cabal view
@@ -1,11 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.20.0.+-- This file has been generated from package.yaml by hpack version 0.21.2. -- -- see: https://github.com/sol/hpack ----- hash: f63250aadbaab3be65345eb28df24e2b368dc8f857f029577525ef698e71540c+-- hash: 27ad120cc4fb815335e1be622df84ce63c95b38332af173a6898e59a80a7c0ad name: backprop-version: 0.1.5.0+version: 0.1.5.1 synopsis: Heterogeneous automatic differentation (backpropagation) description: Write your functions to compute your result, and the library will automatically generate functions to compute your gradient.@@ -47,6 +47,7 @@ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wredundant-constraints -fprint-explicit-kinds build-depends: base >=4.7 && <5+ , binary , deepseq , microlens , primitive
src/Numeric/Backprop/Internal.hs view
@@ -1,10 +1,12 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeInType #-}@@ -53,6 +55,7 @@ import Data.Type.Product hiding (toList) import Data.Type.Util import Data.Type.Vector hiding (itraverse)+import Data.Typeable import GHC.Exts (Any) import GHC.Generics import Lens.Micro@@ -106,6 +109,9 @@ data BVar s a = BV { _bvRef :: !(BRef s) , _bvVal :: !a }++-- | @since 0.1.5.1+deriving instance Typeable (BVar s a) data BRef (s :: Type) = BRInp !Int | BRIx !Int
src/Numeric/Backprop/Tuple.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE BangPatterns #-} {-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DeriveDataTypeable #-}@@ -12,6 +11,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-}@@ -114,6 +114,7 @@ import Lens.Micro.Internal hiding (Index) import Type.Class.Known import Type.Family.List+import qualified Data.Binary as Bi #if !MIN_VERSION_base(4,11,0) import Data.Semigroup@@ -123,29 +124,27 @@ -- -- Be aware that the methods in its numerical instances are all non-strict: ----- @@+-- @ -- _ + _ = 'T0' -- 'negate' _ = 'T0' -- 'fromIntegral' _ = 'T0'--- @@+-- @ -- -- @since 0.1.4.0 data T0 = T0 deriving (Show, Read, Eq, Ord, Generic, Data) -instance NFData T0- -- | Strict 2-tuple with 'Num', 'Fractional', and 'Floating' instances. -- -- @since 0.1.1.0 data T2 a b = T2 !a !b- deriving (Show, Read, Eq, Ord, Generic, Functor, Data)+ deriving (Show, Read, Eq, Ord, Generic, Functor, Data, Typeable) -- | Strict 3-tuple with a 'Num', 'Fractional', and 'Floating' instances. -- -- @since 0.1.1.0 data T3 a b c = T3 !a !b !c- deriving (Show, Read, Eq, Ord, Generic, Functor, Data)+ deriving (Show, Read, Eq, Ord, Generic, Functor, Data, Typeable) -- | Strict inductive N-tuple with a 'Num', 'Fractional', and 'Floating' -- instances.@@ -165,13 +164,39 @@ TNil :: T '[] (:&) :: !a -> !(T as) -> T (a ': as) +-- | @since 0.1.5.1+deriving instance ListC (Show <$> as) => Show (T as)+-- | @since 0.1.5.1+deriving instance ListC (Eq <$> as) => Eq (T as)+-- | @since 0.1.5.1+deriving instance (ListC (Eq <$> as), ListC (Ord <$> as)) => Ord (T as)+-- | @since 0.1.5.1+deriving instance Typeable (T as)++-- | @since 0.1.5.1+deriving instance Typeable T0+-- | @since 0.1.5.1+deriving instance Typeable (T2 a b)+-- | @since 0.1.5.1+deriving instance Typeable (T3 a b c)++instance NFData T0 instance (NFData a, NFData b) => NFData (T2 a b) instance (NFData a, NFData b, NFData c) => NFData (T3 a b c) instance ListC (NFData <$> as) => NFData (T as) where rnf = \case- TNil -> ()- (!_) :& xs -> rnf xs+ TNil -> ()+ x :& xs -> rnf x `seq` rnf xs +-- TODO: optimize++-- | @since 0.1.5.1+instance Bi.Binary T0+-- | @since 0.1.5.1+instance (Bi.Binary a, Bi.Binary b) => Bi.Binary (T2 a b)+-- | @since 0.1.5.1+instance (Bi.Binary a, Bi.Binary b, Bi.Binary c) => Bi.Binary (T3 a b c)+ instance Bifunctor T2 where bimap f g (T2 x y) = T2 (f x) (g y) @@ -587,6 +612,23 @@ instance (Known Length as, ListC (Semigroup <$> as), ListC (Monoid <$> as)) => Monoid (T as) where mempty = constT @Monoid mempty known mappend = (<>)++-- | @since 0.1.5.1+instance (Known Length as, ListC (Bi.Binary <$> as)) => Bi.Binary (T as) where+ put = \case+ TNil -> pure ()+ x :& xs -> do+ Bi.put x+ Bi.put xs+ get = getT known++getT :: ListC (Bi.Binary <$> as) => Length as -> Bi.Get (T as)+getT = \case+ LZ -> pure TNil+ LS l -> do+ x <- Bi.get+ xs <- getT l+ pure (x :& xs) -- $t2iso --