{-# LANGUAGE Rank2Types #-}
module Numeric.AD.Mode.Sparse
( AD, Sparse, auto
, grad
, grad'
, grads
, gradWith
, gradWith'
, jacobian
, jacobian'
, jacobianWith
, jacobianWith'
, jacobians
, hessian
, hessian'
, hessianF
, hessianF'
) where
import Control.Comonad.Cofree (Cofree)
import Numeric.AD.Internal.Sparse (Sparse)
import qualified Numeric.AD.Rank1.Sparse as Rank1
import Numeric.AD.Internal.Type
import Numeric.AD.Mode
grad :: (Traversable f, Num a) => (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> f a
grad :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> f a
grad forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> f a
Rank1.grad (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE grad #-}
grad' :: (Traversable f, Num a) => (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> (a, f a)
grad' :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Sparse a)) -> AD s (Sparse a))
-> f a -> (a, f a)
grad' forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> (a, f a)
Rank1.grad' (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE grad' #-}
gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> f b
gradWith :: forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> f b
gradWith a -> a -> b
g forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b) -> (f (Sparse a) -> Sparse a) -> f a -> f b
Rank1.gradWith a -> a -> b
g (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE gradWith #-}
gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> (a, f b)
gradWith' :: forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Sparse a)) -> AD s (Sparse a))
-> f a
-> (a, f b)
gradWith' a -> a -> b
g forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b) -> (f (Sparse a) -> Sparse a) -> f a -> (a, f b)
Rank1.gradWith' a -> a -> b
g (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE gradWith' #-}
jacobian :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (f a)
jacobian :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a -> g (f a)
jacobian forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (f a)
Rank1.jacobian (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE jacobian #-}
jacobian' :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (a, f a)
jacobian' :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a -> g (a, f a)
jacobian' forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f a)
Rank1.jacobian' (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE jacobian' #-}
jacobianWith :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (f b)
jacobianWith :: forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a
-> g (f b)
jacobianWith a -> a -> b
g forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b) -> (f (Sparse a) -> g (Sparse a)) -> f a -> g (f b)
Rank1.jacobianWith a -> a -> b
g (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE jacobianWith #-}
jacobianWith' :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (a, f b)
jacobianWith' :: forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a
-> g (a, f b)
jacobianWith' a -> a -> b
g forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b)
-> (f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f b)
Rank1.jacobianWith' a -> a -> b
g (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE jacobianWith' #-}
grads :: (Traversable f, Num a) => (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> Cofree f a
grads :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Sparse a)) -> AD s (Sparse a))
-> f a -> Cofree f a
grads forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> Cofree f a
Rank1.grads (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE grads #-}
jacobians :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (Cofree f a)
jacobians :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a -> g (Cofree f a)
jacobians forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (Cofree f a)
Rank1.jacobians (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE jacobians #-}
hessian :: (Traversable f, Num a) => (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> f (f a)
hessian :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Sparse a)) -> AD s (Sparse a))
-> f a -> f (f a)
hessian forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> f (f a)
Rank1.hessian (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE hessian #-}
hessian' :: (Traversable f, Num a) => (forall s. f (AD s (Sparse a)) -> AD s (Sparse a)) -> f a -> (a, f (a, f a))
hessian' :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Sparse a)) -> AD s (Sparse a))
-> f a -> (a, f (a, f a))
hessian' forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f = forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> (a, f (a, f a))
Rank1.hessian' (forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE hessian' #-}
hessianF :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (f (f a))
hessianF :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a -> g (f (f a))
hessianF forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (f (f a))
Rank1.hessianF (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE hessianF #-}
hessianF' :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))) -> f a -> g (a, f (a, f a))
hessianF' :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a)))
-> f a -> g (a, f (a, f a))
hessianF' forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f = forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f (a, f a))
Rank1.hessianF' (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. AD s a -> a
runADforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
fforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s a. a -> AD s a
AD)
{-# INLINE hessianF' #-}