ad 1.0.6 → 1.1.0
raw patch · 4 files changed
+21/−19 lines, 4 filesdep +freedep −streamsPVP ok
version bump matches the API change (PVP)
Dependencies added: free
Dependencies removed: streams
API changes (from Hackage documentation)
- Numeric.AD.Internal.Sparse: instance Num a => Grads (AD Sparse a) (Stream [] a) a
+ Numeric.AD.Internal.Sparse: instance Num a => Grads (AD Sparse a) (Cofree [] a) a
- Numeric.AD.Internal.Sparse: ds :: (Traversable f, Num a) => f b -> AD Sparse a -> Stream f a
+ Numeric.AD.Internal.Sparse: ds :: (Traversable f, Num a) => f b -> AD Sparse a -> Cofree f a
- Numeric.AD.Internal.Sparse: unpacks :: Grads i o a => ([a] -> Stream [] a) -> o
+ Numeric.AD.Internal.Sparse: unpacks :: Grads i o a => ([a] -> Cofree [] a) -> o
- Numeric.AD.Mode.Mixed: grads :: (Traversable f, Num a) => FU f a -> f a -> Stream f a
+ Numeric.AD.Mode.Mixed: grads :: (Traversable f, Num a) => FU f a -> f a -> Cofree f a
- Numeric.AD.Mode.Mixed: jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Stream f a)
+ Numeric.AD.Mode.Mixed: jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Cofree f a)
- Numeric.AD.Mode.Sparse: grads :: (Traversable f, Num a) => FU f a -> f a -> Stream f a
+ Numeric.AD.Mode.Sparse: grads :: (Traversable f, Num a) => FU f a -> f a -> Cofree f a
- Numeric.AD.Mode.Sparse: jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Stream f a)
+ Numeric.AD.Mode.Sparse: jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Cofree f a)
- Numeric.AD.Types: tensors :: Functor f => Stream f a -> Tensors f a
+ Numeric.AD.Types: tensors :: Functor f => Cofree f a -> Tensors f a
Files
- Numeric/AD/Internal/Sparse.hs +6/−6
- Numeric/AD/Internal/Tensors.hs +4/−6
- Numeric/AD/Mode/Sparse.hs +5/−5
- ad.cabal +6/−2
Numeric/AD/Internal/Sparse.hs view
@@ -21,7 +21,7 @@ import Prelude hiding (lookup) import Control.Applicative import Numeric.AD.Internal.Classes-import Data.Stream.Branching+import Control.Comonad.Cofree import Numeric.AD.Internal.Types import Data.Data import Data.Typeable ()@@ -85,11 +85,11 @@ d' fs (AD (Sparse a da)) = (a , snd $ mapAccumL (\ !n _ -> (n + 1, maybe 0 primal $ lookup n da)) 0 fs) {-# INLINE d' #-} -ds :: (Traversable f, Num a) => f b -> AD Sparse a -> Stream f a+ds :: (Traversable f, Num a) => f b -> AD Sparse a -> Cofree f a ds fs (AD as@(Sparse a _)) = a :< (go emptyIndex <$> fns) where fns = skeleton fs- -- go :: Index -> Int -> Stream f a+ -- go :: Index -> Int -> Cofree f a go ix i = partial (indices ix') as :< (go ix' <$> fns) where ix' = addToIndex i ix {-# INLINE ds #-}@@ -112,7 +112,7 @@ vd' n (AD (Sparse a da)) = (a , Vector.generate n $ \i -> maybe 0 primal $ lookup i da) {-# INLINE vd' #-} -vds :: Num a => Int -> AD Sparse a -> Stream Vector a+vds :: Num a => Int -> AD Sparse a -> Cofree Vector a vds n (AD as@(Sparse a _)) = a :< Vector.generate n (go emptyIndex) where go ix i = partial (indices ix') as :< Vector.generate n (go ix')@@ -202,9 +202,9 @@ class Num a => Grads i o a | i -> a o, o -> a i where packs :: i -> [AD Sparse a] -> AD Sparse a- unpacks :: ([a] -> Stream [] a) -> o+ unpacks :: ([a] -> Cofree [] a) -> o -instance Num a => Grads (AD Sparse a) (Stream [] a) a where+instance Num a => Grads (AD Sparse a) (Cofree [] a) a where packs i _ = i unpacks f = f []
Numeric/AD/Internal/Tensors.hs view
@@ -23,11 +23,11 @@ import Data.Traversable import Data.Monoid import Data.Typeable (Typeable1(..), TyCon, mkTyCon, mkTyConApp)-import Data.Stream.Branching as Branching+import Control.Comonad.Cofree infixl 3 :- --- private, unexported type, so any instances for it will be polymorphic+data Tensors f a = a :- Tensors f (f a) newtype Showable = Showable (Int -> String -> String) @@ -39,9 +39,7 @@ -- Polymorphic recursion precludes 'Data' in its current form, as no Data1 class exists -- Polymorphic recursion also breaks 'show' for 'Tensors'!--data Tensors f a = a :- Tensors f (f a)-+-- factor Show1 out of Lifted? instance (Functor f, Show (f Showable), Show a) => Show (Tensors f a) where showsPrec d (a :- as) = showParen (d > 3) $ showsPrec 4 a . showString " :- " . showsPrec 3 (fmap showable <$> as)@@ -63,7 +61,7 @@ headT (a :- _) = a {-# INLINE headT #-} -tensors :: Functor f => Stream f a -> Tensors f a+tensors :: Functor f => Cofree f a -> Tensors f a tensors (a :< as) = a :- dist (tensors <$> as) where dist :: Functor f => f (Tensors f a) -> Tensors f (f a)
Numeric/AD/Mode/Sparse.hs view
@@ -49,7 +49,7 @@ import Control.Comonad import Control.Applicative ((<$>)) import Data.Traversable-import Data.Stream.Branching+import Control.Comonad.Cofree import Numeric.AD.Types import Numeric.AD.Classes import Numeric.AD.Internal.Sparse@@ -91,19 +91,19 @@ jacobianWith' g f as = second (zipWithT g as) <$> jacobian' f as {-# INLINE jacobianWith' #-} -grads :: (Traversable f, Num a) => FU f a -> f a -> Stream f a+grads :: (Traversable f, Num a) => FU f a -> f a -> Cofree f a grads f as = ds as $ apply f as {-# INLINE grads #-} -jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Stream f a)+jacobians :: (Traversable f, Functor g, Num a) => FF f g a -> f a -> g (Cofree f a) jacobians f as = ds as <$> apply f as {-# INLINE jacobians #-} -d2 :: Functor f => Stream f a -> f (f a)+d2 :: Functor f => Cofree f a -> f (f a) d2 = headT . tailT . tailT . tensors {-# INLINE d2 #-} -d2' :: Functor f => Stream f a -> (a, f (a, f a))+d2' :: Functor f => Cofree f a -> (a, f (a, f a)) d2' (a :< as) = (a, fmap (\(da :< das) -> (da, extract <$> das)) as) {-# INLINE d2' #-}
ad.cabal view
@@ -1,5 +1,5 @@ name: ad-version: 1.0.6+version: 1.1.0 license: BSD3 license-File: LICENSE copyright: (c) Edward Kmett 2010-2011,@@ -93,11 +93,15 @@ type: git location: git://github.com/ekmett/ad.git +++ flag TemplateHaskell24 manual: False default: False library + if flag(TemplateHaskell24) build-depends: template-haskell >= 2.4 && < 2.5 extensions: CPP@@ -111,7 +115,7 @@ containers >= 0.2 && < 0.5, array >= 0.2 && < 0.4, comonad >= 1.1 && < 1.2,- streams >= 0.7.1 && < 0.8+ free >= 1.8 && < 1.9 exposed-modules: Numeric.AD