{-# LANGUAGE Rank2Types #-}
module Numeric.AD.Mode.Forward
( AD
, Forward
, auto
, grad
, grad'
, gradWith
, gradWith'
, jacobian
, jacobian'
, jacobianWith
, jacobianWith'
, jacobianT
, jacobianWithT
, hessianProduct
, hessianProduct'
, diff
, diff'
, diffF
, diffF'
, du
, du'
, duF
, duF'
) where
import Numeric.AD.Internal.Forward
import Numeric.AD.Internal.On
import Numeric.AD.Internal.Type
import qualified Numeric.AD.Rank1.Forward as Rank1
import Numeric.AD.Mode
du :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> a
du :: forall (f :: * -> *) a.
(Functor f, Num a) =>
(forall s. f (AD s (Forward a)) -> AD s (Forward a))
-> f (a, a) -> a
du forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (f (Forward a) -> Forward a) -> f (a, a) -> a
forall (f :: * -> *) a.
(Functor f, Num a) =>
(f (Forward a) -> Forward a) -> f (a, a) -> a
Rank1.du (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE du #-}
du' :: (Functor f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f (a, a) -> (a, a)
du' :: forall (f :: * -> *) a.
(Functor f, Num a) =>
(forall s. f (AD s (Forward a)) -> AD s (Forward a))
-> f (a, a) -> (a, a)
du' forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (f (Forward a) -> Forward a) -> f (a, a) -> (a, a)
forall (f :: * -> *) a.
(Functor f, Num a) =>
(f (Forward a) -> Forward a) -> f (a, a) -> (a, a)
Rank1.du' (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE du' #-}
duF :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g a
duF :: forall (f :: * -> *) (g :: * -> *) a.
(Functor f, Functor g, Num a) =>
(forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f (a, a) -> g a
duF forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (f (Forward a) -> g (Forward a)) -> f (a, a) -> g a
forall (f :: * -> *) (g :: * -> *) a.
(Functor f, Functor g, Num a) =>
(f (Forward a) -> g (Forward a)) -> f (a, a) -> g a
Rank1.duF ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE duF #-}
duF' :: (Functor f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f (a, a) -> g (a, a)
duF' :: forall (f :: * -> *) (g :: * -> *) a.
(Functor f, Functor g, Num a) =>
(forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f (a, a) -> g (a, a)
duF' forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (f (Forward a) -> g (Forward a)) -> f (a, a) -> g (a, a)
forall (f :: * -> *) (g :: * -> *) a.
(Functor f, Functor g, Num a) =>
(f (Forward a) -> g (Forward a)) -> f (a, a) -> g (a, a)
Rank1.duF' ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE duF' #-}
diff :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> a
diff :: forall a.
Num a =>
(forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> a
diff forall s. AD s (Forward a) -> AD s (Forward a)
f = (Forward a -> Forward a) -> a -> a
forall a. Num a => (Forward a -> Forward a) -> a -> a
Rank1.diff (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (Forward a -> AD Any (Forward a)) -> Forward a -> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.AD Any (Forward a) -> AD Any (Forward a)
forall s. AD s (Forward a) -> AD s (Forward a)
f(AD Any (Forward a) -> AD Any (Forward a))
-> (Forward a -> AD Any (Forward a))
-> Forward a
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE diff #-}
diff' :: Num a => (forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> (a, a)
diff' :: forall a.
Num a =>
(forall s. AD s (Forward a) -> AD s (Forward a)) -> a -> (a, a)
diff' forall s. AD s (Forward a) -> AD s (Forward a)
f = (Forward a -> Forward a) -> a -> (a, a)
forall a. Num a => (Forward a -> Forward a) -> a -> (a, a)
Rank1.diff' (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (Forward a -> AD Any (Forward a)) -> Forward a -> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.AD Any (Forward a) -> AD Any (Forward a)
forall s. AD s (Forward a) -> AD s (Forward a)
f(AD Any (Forward a) -> AD Any (Forward a))
-> (Forward a -> AD Any (Forward a))
-> Forward a
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE diff' #-}
diffF :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f a
diffF :: forall (f :: * -> *) a.
(Functor f, Num a) =>
(forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f a
diffF forall s. AD s (Forward a) -> f (AD s (Forward a))
f = (Forward a -> f (Forward a)) -> a -> f a
forall (f :: * -> *) a.
(Functor f, Num a) =>
(Forward a -> f (Forward a)) -> a -> f a
Rank1.diffF ((AD Any (Forward a) -> Forward a)
-> f (AD Any (Forward a)) -> f (Forward a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(f (AD Any (Forward a)) -> f (Forward a))
-> (Forward a -> f (AD Any (Forward a)))
-> Forward a
-> f (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.AD Any (Forward a) -> f (AD Any (Forward a))
forall s. AD s (Forward a) -> f (AD s (Forward a))
f(AD Any (Forward a) -> f (AD Any (Forward a)))
-> (Forward a -> AD Any (Forward a))
-> Forward a
-> f (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE diffF #-}
diffF' :: (Functor f, Num a) => (forall s. AD s (Forward a) -> f (AD s (Forward a))) -> a -> f (a, a)
diffF' :: forall (f :: * -> *) a.
(Functor f, Num a) =>
(forall s. AD s (Forward a) -> f (AD s (Forward a)))
-> a -> f (a, a)
diffF' forall s. AD s (Forward a) -> f (AD s (Forward a))
f = (Forward a -> f (Forward a)) -> a -> f (a, a)
forall (f :: * -> *) a.
(Functor f, Num a) =>
(Forward a -> f (Forward a)) -> a -> f (a, a)
Rank1.diffF' ((AD Any (Forward a) -> Forward a)
-> f (AD Any (Forward a)) -> f (Forward a)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(f (AD Any (Forward a)) -> f (Forward a))
-> (Forward a -> f (AD Any (Forward a)))
-> Forward a
-> f (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.AD Any (Forward a) -> f (AD Any (Forward a))
forall s. AD s (Forward a) -> f (AD s (Forward a))
f(AD Any (Forward a) -> f (AD Any (Forward a)))
-> (Forward a -> AD Any (Forward a))
-> Forward a
-> f (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE diffF' #-}
jacobianT :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g a)
jacobianT :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a -> f (g a)
jacobianT forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (f (Forward a) -> g (Forward a)) -> f a -> f (g a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Functor g, Num a) =>
(f (Forward a) -> g (Forward a)) -> f a -> f (g a)
Rank1.jacobianT ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobianT #-}
jacobianWithT :: (Traversable f, Functor g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> f (g b)
jacobianWithT :: forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a
-> f (g b)
jacobianWithT a -> a -> b
g forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (a -> a -> b) -> (f (Forward a) -> g (Forward a)) -> f a -> f (g b)
forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Functor g, Num a) =>
(a -> a -> b) -> (f (Forward a) -> g (Forward a)) -> f a -> f (g b)
Rank1.jacobianWithT a -> a -> b
g ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobianWithT #-}
jacobian :: (Traversable f, Traversable g, Num a) => (forall s . f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f a)
jacobian :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Traversable g, Num a) =>
(forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a -> g (f a)
jacobian forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (f (Forward a) -> g (Forward a)) -> f a -> g (f a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Traversable g, Num a) =>
(f (Forward a) -> g (Forward a)) -> f a -> g (f a)
Rank1.jacobian ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobian #-}
jacobianWith :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (f b)
jacobianWith :: forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Traversable g, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a
-> g (f b)
jacobianWith a -> a -> b
g forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (a -> a -> b) -> (f (Forward a) -> g (Forward a)) -> f a -> g (f b)
forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Traversable g, Num a) =>
(a -> a -> b) -> (f (Forward a) -> g (Forward a)) -> f a -> g (f b)
Rank1.jacobianWith a -> a -> b
g ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobianWith #-}
jacobian' :: (Traversable f, Traversable g, Num a) => (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f a)
jacobian' :: forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Traversable g, Num a) =>
(forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a -> g (a, f a)
jacobian' forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (f (Forward a) -> g (Forward a)) -> f a -> g (a, f a)
forall (f :: * -> *) (g :: * -> *) a.
(Traversable f, Traversable g, Num a) =>
(f (Forward a) -> g (Forward a)) -> f a -> g (a, f a)
Rank1.jacobian' ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobian' #-}
jacobianWith' :: (Traversable f, Traversable g, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a))) -> f a -> g (a, f b)
jacobianWith' :: forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Traversable g, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Forward a)) -> g (AD s (Forward a)))
-> f a
-> g (a, f b)
jacobianWith' a -> a -> b
g forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f = (a -> a -> b)
-> (f (Forward a) -> g (Forward a)) -> f a -> g (a, f b)
forall (f :: * -> *) (g :: * -> *) a b.
(Traversable f, Traversable g, Num a) =>
(a -> a -> b)
-> (f (Forward a) -> g (Forward a)) -> f a -> g (a, f b)
Rank1.jacobianWith' a -> a -> b
g ((AD Any (Forward a) -> Forward a)
-> g (AD Any (Forward a)) -> g (Forward 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 (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(g (AD Any (Forward a)) -> g (Forward a))
-> (f (Forward a) -> g (AD Any (Forward a)))
-> f (Forward a)
-> g (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> g (AD Any (Forward a))
forall s. f (AD s (Forward a)) -> g (AD s (Forward a))
f(f (AD Any (Forward a)) -> g (AD Any (Forward a)))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> g (AD Any (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE jacobianWith' #-}
grad :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f a
grad :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f a
grad forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (f (Forward a) -> Forward a) -> f a -> f a
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Forward a) -> Forward a) -> f a -> f a
Rank1.grad (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE grad #-}
grad' :: (Traversable f, Num a) => (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f a)
grad' :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s. f (AD s (Forward a)) -> AD s (Forward a))
-> f a -> (a, f a)
grad' forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (f (Forward a) -> Forward a) -> f a -> (a, f a)
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (Forward a) -> Forward a) -> f a -> (a, f a)
Rank1.grad' (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE grad' #-}
gradWith :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> f b
gradWith :: forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Forward a)) -> AD s (Forward a))
-> f a
-> f b
gradWith a -> a -> b
g forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (a -> a -> b) -> (f (Forward a) -> Forward a) -> f a -> f b
forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b) -> (f (Forward a) -> Forward a) -> f a -> f b
Rank1.gradWith a -> a -> b
g (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE gradWith #-}
gradWith' :: (Traversable f, Num a) => (a -> a -> b) -> (forall s. f (AD s (Forward a)) -> AD s (Forward a)) -> f a -> (a, f b)
gradWith' :: forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b)
-> (forall s. f (AD s (Forward a)) -> AD s (Forward a))
-> f a
-> (a, f b)
gradWith' a -> a -> b
g forall s. f (AD s (Forward a)) -> AD s (Forward a)
f = (a -> a -> b) -> (f (Forward a) -> Forward a) -> f a -> (a, f b)
forall (f :: * -> *) a b.
(Traversable f, Num a) =>
(a -> a -> b) -> (f (Forward a) -> Forward a) -> f a -> (a, f b)
Rank1.gradWith' a -> a -> b
g (AD Any (Forward a) -> Forward a
forall s a. AD s a -> a
runAD(AD Any (Forward a) -> Forward a)
-> (f (Forward a) -> AD Any (Forward a))
-> f (Forward a)
-> Forward a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (Forward a)) -> AD Any (Forward a)
forall s. f (AD s (Forward a)) -> AD s (Forward a)
f(f (AD Any (Forward a)) -> AD Any (Forward a))
-> (f (Forward a) -> f (AD Any (Forward a)))
-> f (Forward a)
-> AD Any (Forward a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Forward a -> AD Any (Forward a))
-> f (Forward a) -> f (AD Any (Forward a))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Forward a -> AD Any (Forward a)
forall s a. a -> AD s a
AD)
{-# INLINE gradWith' #-}
hessianProduct :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f a
hessianProduct :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a))))
-> f (a, a) -> f a
hessianProduct forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a)))
f = (f (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> f (a, a) -> f a
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> f (a, a) -> f a
Rank1.hessianProduct (AD Any (On (Forward (Forward a))) -> On (Forward (Forward a))
forall s a. AD s a -> a
runAD(AD Any (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> (f (On (Forward (Forward a)))
-> AD Any (On (Forward (Forward a))))
-> f (On (Forward (Forward a)))
-> On (Forward (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (On (Forward (Forward a))))
-> AD Any (On (Forward (Forward a)))
forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a)))
f(f (AD Any (On (Forward (Forward a))))
-> AD Any (On (Forward (Forward a))))
-> (f (On (Forward (Forward a)))
-> f (AD Any (On (Forward (Forward a)))))
-> f (On (Forward (Forward a)))
-> AD Any (On (Forward (Forward a)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(On (Forward (Forward a)) -> AD Any (On (Forward (Forward a))))
-> f (On (Forward (Forward a)))
-> f (AD Any (On (Forward (Forward a))))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap On (Forward (Forward a)) -> AD Any (On (Forward (Forward a)))
forall s a. a -> AD s a
AD)
{-# INLINE hessianProduct #-}
hessianProduct' :: (Traversable f, Num a) => (forall s. f (AD s (On (Forward (Forward a)))) -> AD s (On (Forward (Forward a)))) -> f (a, a) -> f (a, a)
hessianProduct' :: forall (f :: * -> *) a.
(Traversable f, Num a) =>
(forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a))))
-> f (a, a) -> f (a, a)
hessianProduct' forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a)))
f = (f (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> f (a, a) -> f (a, a)
forall (f :: * -> *) a.
(Traversable f, Num a) =>
(f (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> f (a, a) -> f (a, a)
Rank1.hessianProduct' (AD Any (On (Forward (Forward a))) -> On (Forward (Forward a))
forall s a. AD s a -> a
runAD(AD Any (On (Forward (Forward a))) -> On (Forward (Forward a)))
-> (f (On (Forward (Forward a)))
-> AD Any (On (Forward (Forward a))))
-> f (On (Forward (Forward a)))
-> On (Forward (Forward a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.f (AD Any (On (Forward (Forward a))))
-> AD Any (On (Forward (Forward a)))
forall s.
f (AD s (On (Forward (Forward a))))
-> AD s (On (Forward (Forward a)))
f(f (AD Any (On (Forward (Forward a))))
-> AD Any (On (Forward (Forward a))))
-> (f (On (Forward (Forward a)))
-> f (AD Any (On (Forward (Forward a)))))
-> f (On (Forward (Forward a)))
-> AD Any (On (Forward (Forward a)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(On (Forward (Forward a)) -> AD Any (On (Forward (Forward a))))
-> f (On (Forward (Forward a)))
-> f (AD Any (On (Forward (Forward a))))
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap On (Forward (Forward a)) -> AD Any (On (Forward (Forward a)))
forall s a. a -> AD s a
AD)
{-# INLINE hessianProduct' #-}