{-# 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 = (f (Sparse a) -> Sparse a) -> f a -> f a
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> f a
Rank1.grad (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> Sparse a) -> f a -> (a, f a)
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> (a, f a)
Rank1.grad' (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (a -> a -> b) -> (f (Sparse a) -> Sparse a) -> f a -> f b
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 (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (a -> a -> b) -> (f (Sparse a) -> Sparse a) -> f a -> (a, f b)
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 (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> g (Sparse a)) -> f a -> g (f a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (f a)
Rank1.jacobian ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f a)
Rank1.jacobian' ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (a -> a -> b) -> (f (Sparse a) -> g (Sparse a)) -> f a -> g (f b)
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 ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (a -> a -> b)
-> (f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f b)
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 ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> Sparse a) -> f a -> Cofree f a
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> Cofree f a
Rank1.grads (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> g (Sparse a)) -> f a -> g (Cofree f a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (Cofree f a)
Rank1.jacobians ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> Sparse a) -> f a -> f (f a)
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> f (f a)
Rank1.hessian (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> Sparse a) -> f a -> (a, f (a, f a))
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Sparse a) -> Sparse a) -> f a -> (a, f (a, f a))
Rank1.hessian' (AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(AD Any (Sparse a) -> Sparse a)
-> (f (Sparse a) -> AD Any (Sparse a)) -> f (Sparse a) -> Sparse a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> AD Any (Sparse a)
forall s. f (AD s (Sparse a)) -> AD s (Sparse a)
f(f (AD Any (Sparse a)) -> AD Any (Sparse a))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> AD Any (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> g (Sparse a)) -> f a -> g (f (f a))
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Sparse a) -> g (Sparse a)) -> f a -> g (f (f a))
Rank1.hessianF ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
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 = (f (Sparse a) -> g (Sparse a)) -> f a -> g (a, f (a, f a))
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' ((AD Any (Sparse a) -> Sparse a)
-> g (AD Any (Sparse a)) -> g (Sparse a)
forall a b. (a -> b) -> g a -> g b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Sparse a) -> Sparse a
forall s a. AD s a -> a
runAD(g (AD Any (Sparse a)) -> g (Sparse a))
-> (f (Sparse a) -> g (AD Any (Sparse a)))
-> f (Sparse a)
-> g (Sparse a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Sparse a)) -> g (AD Any (Sparse a))
forall s. f (AD s (Sparse a)) -> g (AD s (Sparse a))
f(f (AD Any (Sparse a)) -> g (AD Any (Sparse a)))
-> (f (Sparse a) -> f (AD Any (Sparse a)))
-> f (Sparse a)
-> g (AD Any (Sparse a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Sparse a -> AD Any (Sparse a))
-> f (Sparse a) -> f (AD Any (Sparse a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sparse a -> AD Any (Sparse a)
forall s a. a -> AD s a
AD)
{-# INLINE hessianF' #-}