<commit_before>{-# LANGUAGE RankNTypes #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Numeric.AD.Mode.Directed
-- Copyright   :  (c) <NAME> 2010-12
-- License     :  BSD3
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  GHC only
--
-- Allows the choice of AD 'Mode' to be specified at the term level for
-- benchmarking or more complicated usage patterns.
-----------------------------------------------------------------------------

module Numeric.AD.Mode.Directed where
{-
    (
    -- * Gradients
      grad
    , grad'
    -- * Jacobians
    , jacobian
    , jacobian'
    -- * Derivatives
    , diff
    , diff'
    -- * Exposed Types
    , Direction(..)
    ) where

import Prelude hiding (reverse)
import Numeric.AD.Types
import Data.Traversable (Traversable)
import qualified Numeric.AD.Mode.Kahn as K
import qualified Numeric.AD.Mode.Forward as F
import qualified Numeric.AD.Mode.Tower as T
import qualified Numeric.AD.Mode.Reverse as R
import qualified Numeric.AD as M
import Data.Ix

data Direction
    = Forward
    | Kahn
    | Reverse
    | Tower
    | Mixed
    deriving (Show, Eq, Ord, Read, Bounded, Enum, Ix)

diff :: Num a => Direction -> (forall m s. Mode m => AD s m -> AD s m) -> a -> a
diff Forward f a = F.diff f a
diff Kahn f a    = K.diff f a
diff Reverse f a = R.diff f a
diff Tower f a   = T.diff f a
diff Mixed f a   = F.diff f a
{-# INLINE diff #-}

diff' :: Num a => Direction -> (forall m s. Mode m => AD s m -> AD s m) -> a -> (a, a)
diff' Forward f a = F.diff' f a
diff' Kahn f a    = K.diff' f a
diff' Reverse f a = R.diff' f a
diff' Tower f a   = T.diff' f a
diff' Mixed f a   = F.diff' f a
{-# INLINE diff' #-}

jacobian :: (Traversable f, Traversable g, Num a) => Direction -> (forall m s. Mode m => f (AD s m) -> g (AD s m)) -> f a -> g (f a)
jacobian Forward f a = F.jacobian f a
jacobian Kahn f a    = K.jacobian f a
jacobian Reverse f a = R.jacobian f a
jacobian Tower f a   = F.jacobian f a -- error "jacobian Tower: unimplemented"
jacobian Mixed f a   = M.jacobian f a
{-# INLINE jacobian #-}

jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> (forall m s. Mode m => f (AD s m) -> g (AD s m)) -> f a -> g (a, f a)
jacobian' Forward f a = F.jacobian' f a
jacobian' Kahn f a    = K.jacobian' f a
jacobian' Reverse f a = R.jacobian' f a
jacobian' Tower f a   = F.jacobian' f a -- error "jacobian' Tower: unimplemented"
jacobian' Mixed f a   = M.jacobian' f a
{-# INLINE jacobian' #-}

grad :: (Traversable f, Num a) => Direction -> (forall m s. Mode m => f (AD s m) -> AD s m) -> f a -> f a
grad Forward f a = F.grad f a
grad Kahn f a    = K.grad f a
grad Reverse f a = R.grad f a
grad Tower f a   = F.grad f a -- error "grad Tower: unimplemented"
grad Mixed f a   = M.grad f a
{-# INLINE grad #-}

grad' :: (Traversable f, Num a) => Direction -> (forall m s. Mode m => f (AD s m) -> AD s m) -> f a -> (a, f a)
grad' Forward f a = F.grad' f a
grad' Kahn f a    = K.grad' f a
grad' Reverse f a = R.grad' f a
grad' Tower f a   = F.grad' f a -- error "grad' Tower: unimplemented"
grad' Mixed f a   = M.grad' f a
{-# INLINE grad' #-}
-}<commit_msg>Uncomment Numeric.AD.Mode.Directed<commit_after>{-# LANGUAGE RankNTypes #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Numeric.AD.Mode.Directed
-- Copyright   :  (c) <NAME> 2010-12
-- License     :  BSD3
-- Maintainer  :  <EMAIL>
-- Stability   :  experimental
-- Portability :  GHC only
--
-- Allows the choice of AD 'Mode' to be specified at the term level for
-- benchmarking or more complicated usage patterns.
-----------------------------------------------------------------------------

module Numeric.AD.Mode.Directed
    (
    -- * Gradients
      grad
    , grad'
    -- * Jacobians
    , jacobian
    , jacobian'
    -- * Derivatives
    , diff
    , diff'
    -- * Exposed Types
    , Direction(..)
    ) where

import Prelude hiding (reverse)
import Numeric.AD.Types
import Data.Traversable (Traversable)
import qualified Numeric.AD.Mode.Kahn as K
import qualified Numeric.AD.Mode.Forward as F
import qualified Numeric.AD.Mode.Tower as T
import qualified Numeric.AD.Mode.Reverse as R
import qualified Numeric.AD as M
import Data.Ix

data Direction
    = Forward
    | Kahn
    | Reverse
    | Tower
    | Mixed
    deriving (Show, Eq, Ord, Read, Bounded, Enum, Ix)

diff :: Num a => Direction -> (forall m s. Mode m s => m s -> m s) -> a -> a
diff Forward f a = F.diff f a
diff Kahn f a    = K.diff f a
diff Reverse f a = R.diff f a
diff Tower f a   = T.diff f a
diff Mixed f a   = F.diff f a
{-# INLINE diff #-}

diff' :: Num a => Direction -> (forall m s. Mode m s => m s -> m s) -> a -> (a, a)
diff' Forward f a = F.diff' f a
diff' Kahn f a    = K.diff' f a
diff' Reverse f a = R.diff' f a
diff' Tower f a   = T.diff' f a
diff' Mixed f a   = F.diff' f a
{-# INLINE diff' #-}

jacobian :: (Traversable f, Traversable g, Num a) => Direction -> (forall m s. Mode m s => f (m s) -> g (m s)) -> f a -> g (f a)
jacobian Forward f a = F.jacobian f a
jacobian Kahn f a    = K.jacobian f a
jacobian Reverse f a = R.jacobian f a
jacobian Tower f a   = F.jacobian f a -- error "jacobian Tower: unimplemented"
jacobian Mixed f a   = M.jacobian f a
{-# INLINE jacobian #-}

jacobian' :: (Traversable f, Traversable g, Num a) => Direction -> (forall m s. Mode m s => f (m s) -> g (m s)) -> f a -> g (a, f a)
jacobian' Forward f a = F.jacobian' f a
jacobian' Kahn f a    = K.jacobian' f a
jacobian' Reverse f a = R.jacobian' f a
jacobian' Tower f a   = F.jacobian' f a -- error "jacobian' Tower: unimplemented"
jacobian' Mixed f a   = M.jacobian' f a
{-# INLINE jacobian' #-}

grad :: (Traversable f, Num a) => Direction -> (forall m s. Mode m s => f (m s) -> m s) -> f a -> f a
grad Forward f a = F.grad f a
grad Kahn f a    = K.grad f a
grad Reverse f a = R.grad f a
grad Tower f a   = F.grad f a -- error "grad Tower: unimplemented"
grad Mixed f a   = M.grad f a
{-# INLINE grad #-}

grad' :: (Traversable f, Num a) => Direction -> (forall m s. Mode m s => f (m s) -> m s) -> f a -> (a, f a)
grad' Forward f a = F.grad' f a
grad' Kahn f a    = K.grad' f a
grad' Reverse f a = R.grad' f a
grad' Tower f a   = F.grad' f a -- error "grad' Tower: unimplemented"
grad' Mixed f a   = M.grad' f a
{-# INLINE grad' #-}
{'fraction_non_alphanumeric': 0.1772291240761126, 'fraction_numerical': 0.0022016040257902187, 'mean_word_length': 2.0430622009569377, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '904541', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2313, 'n_words': 946}