ad 0.46.2 → 0.47.0
raw patch · 6 files changed
+11/−104 lines, 6 filesdep +streamsdep ~comonad
Dependencies added: streams
Dependency ranges changed: comonad
Files
- Numeric/AD/Internal/Sparse.hs +1/−1
- Numeric/AD/Internal/Stream.hs +0/−89
- Numeric/AD/Internal/Tensors.hs +4/−4
- Numeric/AD/Mode/Sparse.hs +3/−1
- Numeric/AD/Types.hs +0/−6
- ad.cabal +3/−3
Numeric/AD/Internal/Sparse.hs view
@@ -21,7 +21,7 @@ import Prelude hiding (lookup) import Control.Applicative import Numeric.AD.Internal.Classes-import Numeric.AD.Internal.Stream+import Data.Stream.Branching import Numeric.AD.Internal.Types import Data.Data import Data.Typeable ()
− Numeric/AD/Internal/Stream.hs
@@ -1,89 +0,0 @@-{-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances #-}-{-# OPTIONS_HADDOCK hide #-}--------------------------------------------------------------------------------- |--- Module : Numeric.AD.Internal.Stream--- Copyright : (c) Edward Kmett 2010--- License : BSD3--- Maintainer : ekmett@gmail.com--- Stability : experimental--- Portability : GHC only-----------------------------------------------------------------------------------module Numeric.AD.Internal.Stream - ( Stream(..)- , unfoldS- , headS- , tailS- ) where--import Control.Applicative-import Control.Comonad-import Data.Monoid-import Data.Foldable-import Data.Traversable-import Data.Data (Data(..), mkDataType, DataType, mkConstr, Constr, constrIndex, Fixity(Infix))-import Data.Typeable (Typeable1(..), TyCon, mkTyCon, mkTyConApp, gcast1)--infixl 3 :<--data Stream f a = a :< f (Stream f a)--deriving instance (Show a, Show (f (Stream f a))) => Show (Stream f a)--instance Functor f => Functor (Stream f) where- fmap f (a :< as) = f a :< fmap f <$> as--instance Functor f => Comonad (Stream f) where- extract (a :< _) = a- duplicate aas@(_ :< as) = aas :< duplicate <$> as- extend f aas@(_ :< as) = f aas :< extend f <$> as--instance Foldable f => Foldable (Stream f) where- foldMap f (a :< as) = f a `mappend` foldMap (foldMap f) as--instance Traversable f => Traversable (Stream f) where- traverse f (a :< as) = (:<) <$> f a <*> traverse (traverse f) as--headS :: Stream f a -> a-headS (a :< _) = a-{-# INLINE headS #-}---- tails of the f-branching stream comonad/cofree comonad-tailS :: Stream f a -> f (Stream f a)-tailS (_ :< as) = as-{-# INLINE tailS #-}---unfoldS :: Functor f => (a -> (b, f a)) -> a -> Stream f b-unfoldS f a = h :< unfoldS f <$> t - where- (h, t) = f a--instance Typeable1 f => Typeable1 (Stream f) where- typeOf1 tfa = mkTyConApp streamTyCon [typeOf1 (undefined `asArgsType` tfa)]- where asArgsType :: f a -> t f a -> f a- asArgsType = const--streamTyCon :: TyCon-streamTyCon = mkTyCon "Numeric.AD.Internal.Stream.Stream"-{-# NOINLINE streamTyCon #-}--consConstr :: Constr-consConstr = mkConstr streamDataType "(:<)" [] Infix-{-# NOINLINE consConstr #-}--streamDataType :: DataType-streamDataType = mkDataType "Numeric.AD.Internal.Stream.Stream" [consConstr]-{-# NOINLINE streamDataType #-}--instance (Typeable1 f, Data (f (Stream f a)), Data a) => Data (Stream f a) where- gfoldl f z (a :< as) = z (:<) `f` a `f` as- toConstr _ = consConstr- gunfold k z c = case constrIndex c of- 1 -> k (k (z (:<)))- _ -> error "gunfold"- dataTypeOf _ = streamDataType- dataCast1 f = gcast1 f-
Numeric/AD/Internal/Tensors.hs view
@@ -23,7 +23,7 @@ import Data.Traversable import Data.Monoid import Data.Typeable (Typeable1(..), TyCon, mkTyCon, mkTyConApp)-import Numeric.AD.Internal.Stream+import Data.Stream.Branching as Branching infixl 3 :- @@ -50,10 +50,10 @@ {-# INLINE headT #-} tensors :: Functor f => Stream f a -> Tensors f a-tensors (a :< as) = a :- distribute (tensors <$> as)+tensors (a :< as) = a :- dist (tensors <$> as) where- distribute :: Functor f => f (Tensors f a) -> Tensors f (f a)- distribute x = (headT <$> x) :- distribute (tailT <$> x)+ dist :: Functor f => f (Tensors f a) -> Tensors f (f a)+ dist x = (headT <$> x) :- dist (tailT <$> x) instance Typeable1 f => Typeable1 (Tensors f) where typeOf1 tfa = mkTyConApp tensorsTyCon [typeOf1 (undefined `asArgsType` tfa)]
Numeric/AD/Mode/Sparse.hs view
@@ -46,8 +46,10 @@ , Grads ) where +import Control.Comonad import Control.Applicative ((<$>)) import Data.Traversable+import Data.Stream.Branching import Numeric.AD.Types import Numeric.AD.Classes import Numeric.AD.Internal.Sparse@@ -102,7 +104,7 @@ {-# INLINE d2 #-} d2' :: Functor f => Stream f a -> (a, f (a, f a))-d2' (a :< as) = (a, fmap (\(da :< das) -> (da, fmap headS das)) as)+d2' (a :< as) = (a, fmap (\(da :< das) -> (da, extract <$> das)) as) {-# INLINE d2' #-} hessian :: (Traversable f, Num a) => FU f a -> f a -> f (f a)
Numeric/AD/Types.hs view
@@ -20,11 +20,6 @@ , headT , tailT , tensors- -- * f-Branching Streams- , Stream(..)- , headS- , tailS- , unfoldS -- * An Identity Mode. , Id(..) , probe, unprobe@@ -35,7 +30,6 @@ import Numeric.AD.Internal.Identity import Numeric.AD.Internal.Types-import Numeric.AD.Internal.Stream import Numeric.AD.Internal.Tensors -- these exploit the 'magic' that is probed to avoid the need for Functor, etc.
ad.cabal view
@@ -1,5 +1,5 @@ name: ad-version: 0.46.2+version: 0.47.0 license: BSD3 license-File: LICENSE copyright: (c) Edward Kmett 2010-2011,@@ -87,7 +87,8 @@ containers >= 0.2 && < 0.5, template-haskell >= 2.4 && < 2.5, array >= 0.2 && < 0.4,- comonad >= 0.6 && < 0.9+ comonad >= 0.9 && < 0.10, + streams >= 0.5 && < 0.6 exposed-modules: Numeric.AD@@ -115,7 +116,6 @@ other-modules: Numeric.AD.Internal.Types- Numeric.AD.Internal.Stream Numeric.AD.Internal.Tensors Numeric.AD.Internal.Identity