ad 4.3.5 → 4.3.6
raw patch · 11 files changed
+129/−51 lines, 11 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Numeric.AD: }
- Numeric.AD.Internal.Identity: instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Numeric.AD.Internal.Identity.Id a)
- Numeric.AD.Internal.Kahn: instance (Data.Data.Data t, Data.Data.Data a) => Data.Data.Data (Numeric.AD.Internal.Kahn.Tape a t)
- Numeric.AD.Internal.Kahn: instance (GHC.Show.Show t, GHC.Show.Show a) => GHC.Show.Show (Numeric.AD.Internal.Kahn.Tape a t)
- Numeric.AD.Internal.Or: instance (Numeric.AD.Mode.Mode a, Numeric.AD.Mode.Mode b, Numeric.AD.Internal.Or.Chosen s, Numeric.AD.Mode.Scalar a ~ Numeric.AD.Mode.Scalar b) => Numeric.AD.Mode.Mode (Numeric.AD.Internal.Or.Or s a b)
+ Numeric.AD.Internal.Identity: instance GHC.Base.Semigroup a => GHC.Base.Semigroup (Numeric.AD.Internal.Identity.Id a)
+ Numeric.AD.Internal.Kahn: instance (Data.Data.Data a, Data.Data.Data t) => Data.Data.Data (Numeric.AD.Internal.Kahn.Tape a t)
+ Numeric.AD.Internal.Kahn: instance (GHC.Show.Show a, GHC.Show.Show t) => GHC.Show.Show (Numeric.AD.Internal.Kahn.Tape a t)
+ Numeric.AD.Internal.Or: instance (Numeric.AD.Mode.Mode a, Numeric.AD.Mode.Mode b, Numeric.AD.Internal.Or.Chosen s, Numeric.AD.Mode.Scalar a Data.Type.Equality.~ Numeric.AD.Mode.Scalar b) => Numeric.AD.Mode.Mode (Numeric.AD.Internal.Or.Or s a b)
+ Numeric.AD.Jet: infixl 3 :-
+ Numeric.AD.Mode: infixl 7 ^*
+ Numeric.AD.Mode: infixr 7 ^/
- Numeric.AD: class (Num t, Num (Scalar t)) => Mode t where {
+ Numeric.AD: class (Num t, Num (Scalar t)) => Mode t
- Numeric.AD: type family Scalar t;
+ Numeric.AD: type family Scalar t
- Numeric.AD.Internal.Dense: Dense :: !a -> (f a) -> Dense f a
+ Numeric.AD.Internal.Dense: Dense :: !a -> f a -> Dense f a
- Numeric.AD.Internal.Kahn: Kahn :: (Tape a (Kahn a)) -> Kahn a
+ Numeric.AD.Internal.Kahn: Kahn :: Tape a (Kahn a) -> Kahn a
- Numeric.AD.Internal.Sparse: Monomial :: (IntMap Int) -> Monomial
+ Numeric.AD.Internal.Sparse: Monomial :: IntMap Int -> Monomial
- Numeric.AD.Internal.Sparse: Sparse :: !a -> (IntMap (Sparse a)) -> Sparse a
+ Numeric.AD.Internal.Sparse: Sparse :: !a -> IntMap (Sparse a) -> Sparse a
- Numeric.AD.Mode.Reverse: hessian :: (Traversable f, Num a) => (forall s s'. (Reifies s Tape, Reifies s' Tape) => f (On (Reverse s (Reverse s' a))) -> (On (Reverse s (Reverse s' a)))) -> f a -> f (f a)
+ Numeric.AD.Mode.Reverse: hessian :: (Traversable f, Num a) => (forall s s'. (Reifies s Tape, Reifies s' Tape) => f (On (Reverse s (Reverse s' a))) -> On (Reverse s (Reverse s' a))) -> f a -> f (f a)
- Numeric.AD.Rank1.Kahn: hessian :: (Traversable f, Num a) => (f (On (Kahn (Kahn a))) -> (On (Kahn (Kahn a)))) -> f a -> f (f a)
+ Numeric.AD.Rank1.Kahn: hessian :: (Traversable f, Num a) => (f (On (Kahn (Kahn a))) -> On (Kahn (Kahn a))) -> f a -> f (f a)
Files
- .ghci +0/−1
- .travis.yml +40/−35
- CHANGELOG.markdown +4/−0
- ad.cabal +13/−6
- src/Numeric/AD.hs +6/−2
- src/Numeric/AD/Internal/Doctest.hs +36/−0
- src/Numeric/AD/Internal/Or.hs +14/−0
- src/Numeric/AD/Internal/Sparse.hs +1/−1
- src/Numeric/AD/Mode/Kahn.hs +5/−2
- src/Numeric/AD/Mode/Reverse.hs +5/−2
- src/Numeric/AD/Rank1/Kahn.hs +5/−2
− .ghci
@@ -1,1 +0,0 @@-:set -isrc -idist/build/autogen -optP-include -optPdist/build/autogen/cabal_macros.h -optP-include -optPinclude
.travis.yml view
@@ -1,8 +1,8 @@ # This Travis job script has been generated by a script via #-# runghc make_travis_yml_2.hs '-o' '.travis.yml' '--irc-channel=irc.freenode.org#haskell-lens' '--no-no-tests-no-bench' '--no-installed' 'cabal.project'+# runghc make_travis_yml_2.hs '-o' '.travis.yml' '--ghc-head' '--irc-channel=irc.freenode.org#haskell-lens' '--no-no-tests-no-bench' '--no-unconstrained' 'cabal.project' #-# For more information, see https://github.com/hvr/multi-ghc-travis+# For more information, see https://github.com/haskell-CI/haskell-ci # language: c sudo: false@@ -34,42 +34,37 @@ - rm -rfv $HOME/.cabal/packages/head.hackage -addons:- apt:- packages: &apt_packages- - ghc-ppa-tools- - alex-3.1.7- - happy-1.19.5- matrix: include:- - compiler: "ghc-7.4.2"+ - compiler: "ghc-8.6.3" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.4.2], sources: [hvr-ghc]}}- - compiler: "ghc-7.6.3"+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.6.3], sources: [hvr-ghc]}}+ - compiler: "ghc-8.4.4" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.6.3], sources: [hvr-ghc]}}- - compiler: "ghc-7.8.4"+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.4.4], sources: [hvr-ghc]}}+ - compiler: "ghc-8.2.2" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.8.4], sources: [hvr-ghc]}}+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.2.2], sources: [hvr-ghc]}}+ - compiler: "ghc-8.0.2"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-8.0.2], sources: [hvr-ghc]}} - compiler: "ghc-7.10.3" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-7.10.3], sources: [hvr-ghc]}}- - compiler: "ghc-8.0.2"+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.10.3], sources: [hvr-ghc]}}+ - compiler: "ghc-7.8.4" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-8.0.2], sources: [hvr-ghc]}}- - compiler: "ghc-8.2.2"+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.8.4], sources: [hvr-ghc]}}+ - compiler: "ghc-7.6.3" # env: TEST=--disable-tests BENCH=--disable-benchmarks- addons: {apt: {packages: [*apt_packages,cabal-install-2.0,ghc-8.2.2], sources: [hvr-ghc]}}- - compiler: "ghc-8.4.1"- env: GHCHEAD=true- addons: {apt: {packages: [*apt_packages,cabal-install-head,ghc-8.4.1], sources: [hvr-ghc]}}+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.6.3], sources: [hvr-ghc]}}+ - compiler: "ghc-7.4.2"+ # env: TEST=--disable-tests BENCH=--disable-benchmarks+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-2.4,ghc-7.4.2], sources: [hvr-ghc]}} - compiler: "ghc-head" env: GHCHEAD=true- addons: {apt: {packages: [*apt_packages,cabal-install-head,ghc-head], sources: [hvr-ghc]}}+ addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-head], sources: [hvr-ghc]}} allow_failures:- - compiler: "ghc-8.4.1" - compiler: "ghc-head" before_install:@@ -88,7 +83,8 @@ - BENCH=${BENCH---enable-benchmarks} - TEST=${TEST---enable-tests} - HADDOCK=${HADDOCK-true}- - INSTALLED=${INSTALLED-true}+ - UNCONSTRAINED=${UNCONSTRAINED-true}+ - NOINSTALLEDCONSTRAINTS=${NOINSTALLEDCONSTRAINTS-false} - GHCHEAD=${GHCHEAD-false} - travis_retry cabal update -v - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"@@ -96,7 +92,8 @@ # Overlay Hackage Package Index for GHC HEAD: https://github.com/hvr/head.hackage - | if $GHCHEAD; then- sed -i.bak 's/-- allow-newer:.*/allow-newer: *:base, *:template-haskell, *:ghc, *:Cabal/' ${HOME}/.cabal/config+ sed -i 's/-- allow-newer: .*/allow-newer: *:base/' ${HOME}/.cabal/config+ for pkg in $($HCPKG list --simple-output); do pkg=$(echo $pkg | sed 's/-[^-]*$//'); sed -i "s/allow-newer: /allow-newer: *:$pkg, /" ${HOME}/.cabal/config; done echo 'repository head.hackage' >> ${HOME}/.cabal/config echo ' url: http://head.hackage.haskell.org/' >> ${HOME}/.cabal/config@@ -106,30 +103,39 @@ echo ' 8f79fd2389ab2967354407ec852cbe73f2e8635793ac446d09461ffb99527f6e' >> ${HOME}/.cabal/config echo ' key-threshold: 3' >> ${HOME}/.cabal.config + grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'+ cabal new-update head.hackage -v fi - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$' - "printf 'packages: \".\"\\n' > cabal.project"- - cat cabal.project+ - "printf 'write-ghc-environment-files: always\\n' >> cabal.project"+ - touch cabal.project.local+ - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- ad | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+ - cat cabal.project || true+ - cat cabal.project.local || true - if [ -f "./configure.ac" ]; then (cd "." && autoreconf -i); fi - rm -f cabal.project.freeze - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2 all- - rm -rf "."/.ghc.environment.* "."/dist+ - rm -rf .ghc.environment.* "."/dist - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX) # Here starts the actual work to be performed for the package under test; # any command which exits with a non-zero exit code causes the build to fail. script: # test that source-distributions can be generated- - (cd "." && cabal sdist)- - mv "."/dist/ad-*.tar.gz ${DISTDIR}/+ - cabal new-sdist all+ - mv dist-newstyle/sdist/*.tar.gz ${DISTDIR}/ - cd ${DISTDIR} || false - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \; - "printf 'packages: ad-*/*.cabal\\n' > cabal.project"- - cat cabal.project-+ - "printf 'write-ghc-environment-files: always\\n' >> cabal.project"+ - touch cabal.project.local+ - "if ! $NOINSTALLEDCONSTRAINTS; then for pkg in $($HCPKG list --simple-output); do echo $pkg | grep -vw -- ad | sed 's/^/constraints: /' | sed 's/-[^-]*$/ installed/' >> cabal.project.local; done; fi"+ - cat cabal.project || true+ - cat cabal.project.local || true # build & run tests, build benchmarks - cabal new-build -w ${HC} ${TEST} ${BENCH} all@@ -139,8 +145,7 @@ - (cd ad-* && cabal check) # haddock- - rm -rf ./dist-newstyle - if $HADDOCK; then cabal new-haddock -w ${HC} ${TEST} ${BENCH} all; else echo "Skipping haddock generation";fi -# REGENDATA ["-o",".travis.yml","--irc-channel=irc.freenode.org#haskell-lens","--no-no-tests-no-bench","--no-installed","cabal.project"]+# REGENDATA ["-o",".travis.yml","--ghc-head","--irc-channel=irc.freenode.org#haskell-lens","--no-no-tests-no-bench","--no-unconstrained","cabal.project"] # EOF
CHANGELOG.markdown view
@@ -1,3 +1,7 @@+4.3.6 [2019.02.28]+------------------+* Make the test suite pass when built against `musl` `libc`.+ 4.3.5 [2018.01.18] ------------------ * Add `Semigroup` instance for `Id`.
ad.cabal view
@@ -1,5 +1,5 @@ name: ad-version: 4.3.5+version: 4.3.6 license: BSD3 license-File: LICENSE copyright: (c) Edward Kmett 2010-2015,@@ -12,10 +12,16 @@ bug-reports: http://github.com/ekmett/ad/issues build-type: Custom cabal-version: >= 1.10-tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.1+tested-with: GHC == 7.4.2+ , GHC == 7.6.3+ , GHC == 7.8.4+ , GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.4+ , GHC == 8.6.3 synopsis: Automatic Differentiation extra-source-files:- .ghci .gitignore .travis.yml .vim.custom@@ -113,10 +119,10 @@ array >= 0.2 && < 0.6, base >= 4.3 && < 5, comonad >= 4 && < 6,- containers >= 0.2 && < 0.6,+ containers >= 0.2 && < 0.7, data-reify >= 0.6 && < 0.7, erf >= 2.0 && < 2.1,- free >= 4.6.1 && < 5,+ free >= 4.6.1 && < 6, nats >= 0.1.2 && < 2, reflection >= 1.4 && < 3, semigroups >= 0.16 && < 1,@@ -165,6 +171,7 @@ Numeric.AD.Rank1.Tower other-modules:+ Numeric.AD.Internal.Doctest Numeric.AD.Internal.Combinators ghc-options: -Wall@@ -180,7 +187,7 @@ ad, base, directory,- doctest >= 0.9.0.1 && < 0.14,+ doctest >= 0.9.0.1 && < 0.17, filepath ghc-options: -Wall -threaded hs-source-dirs: tests
src/Numeric/AD.hs view
@@ -172,6 +172,10 @@ import Numeric.AD.Newton +-- $setup+--+-- >>> import Numeric.AD.Internal.Doctest+ -- | @'hessianProduct' f wv@ computes the product of the hessian @H@ of a non-scalar-to-scalar function @f@ at @w = 'fst' <$> wv@ with a vector @v = snd <$> wv@ using \"Pearlmutter\'s method\" from <http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.6143>, which states: -- -- > H v = (d/dr) grad_w (w + r v) | r = 0@@ -198,8 +202,8 @@ -- | Compute the order 3 Hessian tensor on a non-scalar-to-non-scalar function using 'Sparse'-on-'Reverse' ----- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2]--- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.1312043837568135,-2.4717266720048188],[-2.4717266720048188,1.1312043837568135]]]+-- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble]+-- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.131204383757,-2.471726672005],[-2.471726672005,1.131204383757]]] hessianF :: (Traversable f, Functor g, Num a) => (forall s. Reifies s Tape => f (On (Reverse s (Sparse a))) -> g (On (Reverse s (Sparse a)))) -> f a -> g (f (f a)) hessianF f as = getCompose $ Sparse1.jacobian (Compose . Reverse.jacobian (fmap off . f . fmap On)) as
+ src/Numeric/AD/Internal/Doctest.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}++-----------------------------------------------------------------------------+-- |+-- Copyright : (c) Edward Kmett 2010-2019+-- License : BSD3+-- Maintainer : ekmett@gmail.com+-- Stability : experimental+-- Portability : GHC only+--+-- A version of 'Double' that rounds to the twelfth digit if necessary. This+-- is useful for @ad@'s doctests since they must print out floating-point+-- numbers in their entirety, but the actual numbers that get produced can+-- vary slightly depending on machine-specific implementation details.+-- (See #73 for an example.) This works around the issue by just rounding+-- up the printed result to a point where it should be consistent across+-- all machines.+-----------------------------------------------------------------------------+module Numeric.AD.Internal.Doctest (RDouble) where++import GHC.Float+import Numeric++newtype RDouble = RDouble Double+ deriving (Floating, Fractional, Num)++instance Show RDouble where+ showsPrec p (RDouble d)+ | length is' >= limit+ = showSignedFloat (showGFloat (Just limit)) p d+ | otherwise+ = showsPrec p d+ where+ limit = 12+ (is, e) = floatToDigits 10 (abs d)+ is' = drop e is
src/Numeric/AD/Internal/Or.hs view
@@ -58,7 +58,9 @@ binary :: (a -> a -> a) -> (b -> b -> b) -> Or s a b -> Or s a b -> Or s a b binary f _ (L a) (L b) = L (f a b) binary _ g (R a) (R b) = R (g a b)+#if __GLASGOW_HASKELL__ < 800 binary _ _ _ _ = impossible+#endif data F data T@@ -82,18 +84,24 @@ #endif #endif +#if __GLASGOW_HASKELL__ < 800 impossible :: a impossible = error "Numeric.AD.Internal.Or: impossible case"+#endif instance (Eq a, Eq b) => Eq (Or s a b) where L a == L b = a == b R a == R b = a == b+#if __GLASGOW_HASKELL__ < 800 _ == _ = impossible+#endif instance (Ord a, Ord b) => Ord (Or s a b) where L a `compare` L b = compare a b R a `compare` R b = compare a b+#if __GLASGOW_HASKELL__ < 800 _ `compare` _ = impossible+#endif instance (Enum a, Enum b, Chosen s) => Enum (Or s a b) where pred = unary pred pred@@ -104,13 +112,19 @@ enumFrom (R a) = R <$> enumFrom a enumFromThen (L a) (L b) = L <$> enumFromThen a b enumFromThen (R a) (R b) = R <$> enumFromThen a b+#if __GLASGOW_HASKELL__ < 800 enumFromThen _ _ = impossible+#endif enumFromTo (L a) (L b) = L <$> enumFromTo a b enumFromTo (R a) (R b) = R <$> enumFromTo a b+#if __GLASGOW_HASKELL__ < 800 enumFromTo _ _ = impossible+#endif enumFromThenTo (L a) (L b) (L c) = L <$> enumFromThenTo a b c enumFromThenTo (R a) (R b) (R c) = R <$> enumFromThenTo a b c+#if __GLASGOW_HASKELL__ < 800 enumFromThenTo _ _ _ = impossible+#endif instance (Bounded a, Bounded b, Chosen s) => Bounded (Or s a b) where maxBound = choose maxBound maxBound
src/Numeric/AD/Internal/Sparse.hs view
@@ -76,7 +76,7 @@ -- | We only store partials in sorted order, so the map contained in a partial -- will only contain partials with equal or greater keys to that of the map in -- which it was found. This should be key for efficiently computing sparse hessians.--- there are only (n + k - 1) choose (k - 1) distinct nth partial derivatives of a+-- there are only @n + k - 1@ choose @k@ distinct nth partial derivatives of a -- function with k inputs. data Sparse a = Sparse !a (IntMap (Sparse a))
src/Numeric/AD/Mode/Kahn.hs view
@@ -55,6 +55,9 @@ import Numeric.AD.Mode import qualified Numeric.AD.Rank1.Kahn as Rank1 +-- $setup+--+-- >>> import Numeric.AD.Internal.Doctest -- | The 'grad' function calculates the gradient of a non-scalar-to-scalar function with kahn-mode AD in a single pass. --@@ -191,7 +194,7 @@ -- -- Less efficient than 'Numeric.AD.Mode.Mixed.hessianF'. ----- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2]--- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.1312043837568135,-2.4717266720048188],[-2.4717266720048188,1.1312043837568135]]]+-- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble]+-- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.131204383757,-2.471726672005],[-2.471726672005,1.131204383757]]] hessianF :: (Traversable f, Functor g, Num a) => (forall s. f (AD s (On (Kahn (Kahn a)))) -> g (AD s (On (Kahn (Kahn a))))) -> f a -> g (f (f a)) hessianF f = Rank1.hessianF (fmap runAD.f.fmap AD)
src/Numeric/AD/Mode/Reverse.hs view
@@ -55,6 +55,9 @@ import Numeric.AD.Internal.Reverse import Numeric.AD.Mode +-- $setup+--+-- >>> import Numeric.AD.Internal.Doctest -- | The 'grad' function calculates the gradient of a non-scalar-to-scalar function with reverse-mode AD in a single pass. --@@ -202,8 +205,8 @@ -- -- Less efficient than 'Numeric.AD.Mode.Mixed.hessianF'. ----- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2]--- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.1312043837568135,-2.4717266720048188],[-2.4717266720048188,1.1312043837568135]]]+-- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble]+-- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.131204383757,-2.471726672005],[-2.471726672005,1.131204383757]]] hessianF :: (Traversable f, Functor g, Num a) => (forall s s'. (Reifies s Tape, Reifies s' Tape) => f (On (Reverse s (Reverse s' a))) -> g (On (Reverse s (Reverse s' a)))) -> f a -> g (f (f a)) hessianF f = getCompose . jacobian (Compose . jacobian (fmap off . f . fmap On)) {-# INLINE hessianF #-}
src/Numeric/AD/Rank1/Kahn.hs view
@@ -60,6 +60,9 @@ import Numeric.AD.Internal.Kahn import Numeric.AD.Mode +-- $setup+--+-- >>> import Numeric.AD.Internal.Doctest -- | The 'grad' function calculates the gradient of a non-scalar-to-scalar function with kahn-mode AD in a single pass. --@@ -205,8 +208,8 @@ -- -- Less efficient than 'Numeric.AD.Mode.Mixed.hessianF'. ----- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2]--- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.1312043837568135,-2.4717266720048188],[-2.4717266720048188,1.1312043837568135]]]+-- >>> hessianF (\[x,y] -> [x*y,x+y,exp x*cos y]) [1,2 :: RDouble]+-- [[[0.0,1.0],[1.0,0.0]],[[0.0,0.0],[0.0,0.0]],[[-1.131204383757,-2.471726672005],[-2.471726672005,1.131204383757]]] hessianF :: (Traversable f, Functor g, Num a) => (f (On (Kahn (Kahn a))) -> g (On (Kahn (Kahn a)))) -> f a -> g (f (f a)) hessianF f = getCompose . jacobian (Compose . jacobian (fmap off . f . fmap On))