futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | None
Language | GHC2021

Language.Futhark.Interpreter.AD

Synopsis

- data Op
  - = OpBin BinOp
  - | OpCmp CmpOp
  - | OpUn UnOp
  - | OpFn Text
  - | OpConv ConvOp
- data ADVariable
  - = VJP VJPValue
  - | JVP JVPValue
- data ADValue
  - = Variable Depth ADVariable
  - | Constant PrimValue
- data Tape
  - = TapeID Counter ADValue
  - | TapeConst ADValue
  - | TapeOp Op [Tape] Counter ADValue
- newtype VJPValue = VJPValue Tape
- data JVPValue = JVPValue ADValue ADValue
- newtype Counter = Counter Int
- newtype Depth = Depth Int
- doOp :: Op -> [ADValue] -> Counter -> Either String (ADValue, Counter)
- addFor :: PrimType -> BinOp
- tapePrimal :: Tape -> ADValue
- primitive :: ADValue -> PrimValue
- varPrimal :: ADVariable -> PrimValue
- deriveTape :: Tape -> ADValue -> Counter -> Either String (Map Counter ADValue, Counter)
- unionWithM :: (Monad m, Ord k) => (a -> a -> m a) -> Map k a -> Map k a -> m (Map k a)
- unionsWithM :: (Foldable f, Monad m, Ord k) => (a -> a -> m a) -> f (Map k a) -> m (Map k a)

# Documentation

data Op Source #

Constructors

OpBin BinOp |
OpCmp CmpOp |
OpUn UnOp |
OpFn Text |
OpConv ConvOp |

#### Instances

Instances details

Show Op Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> Op -> ShowS Source # show :: Op -> String Source # showList :: [Op] -> ShowS Source #

data ADVariable Source #

Constructors

VJP VJPValue |
JVP JVPValue |

#### Instances

Instances details

Show ADVariable Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> ADVariable -> ShowS Source # show :: ADVariable -> String Source # showList :: [ADVariable] -> ShowS Source #

data ADValue Source #

Constructors

Variable Depth ADVariable |
Constant PrimValue |

#### Instances

Instances details

Show ADValue Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> ADValue -> ShowS Source # show :: ADValue -> String Source # showList :: [ADValue] -> ShowS Source #

data Tape Source #

Represents a computation tree, as well as every intermediate value in its evaluation.

Constructors

TapeID Counter ADValue | This represents a variable. Each variable is given a unique ID, and has an initial value
TapeConst ADValue | This represents a constant.
TapeOp Op [Tape] Counter ADValue | This represents the application of a mathematical operation. Each parameter is given by its Tape, and the return value of the operation is saved

#### Instances

Instances details

Show Tape Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> Tape -> ShowS Source # show :: Tape -> String Source # showList :: [Tape] -> ShowS Source #

newtype VJPValue Source #

Constructors

VJPValue Tape |

#### Instances

Instances details

Show VJPValue Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> VJPValue -> ShowS Source # show :: VJPValue -> String Source # showList :: [VJPValue] -> ShowS Source #

data JVPValue Source #

In JVP, the derivative of the variable must be saved. This is represented as a second value.

Constructors

JVPValue ADValue ADValue |

#### Instances

Instances details

Show JVPValue Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> JVPValue -> ShowS Source # show :: JVPValue -> String Source # showList :: [JVPValue] -> ShowS Source #

newtype Counter Source #

Used to uniquely identify values.

Constructors

Counter Int |

#### Instances

Instances details

Num Counter Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods (+) :: Counter -> Counter -> Counter Source # (-) :: Counter -> Counter -> Counter Source # (*) :: Counter -> Counter -> Counter Source # negate :: Counter -> Counter Source # abs :: Counter -> Counter Source # signum :: Counter -> Counter Source # fromInteger :: Integer -> Counter Source #
Show Counter Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> Counter -> ShowS Source # show :: Counter -> String Source # showList :: [Counter] -> ShowS Source #
Eq Counter Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods (==) :: Counter -> Counter -> Bool Source # (/=) :: Counter -> Counter -> Bool Source #
Ord Counter Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods compare :: Counter -> Counter -> Ordering Source # (<) :: Counter -> Counter -> Bool Source # (<=) :: Counter -> Counter -> Bool Source # (>) :: Counter -> Counter -> Bool Source # (>=) :: Counter -> Counter -> Bool Source # max :: Counter -> Counter -> Counter Source # min :: Counter -> Counter -> Counter Source #

newtype Depth Source #

An indication of the nesting depth of AD. This is used to avoid pertubation confusion.

Constructors

Depth Int |

#### Instances

Instances details

Show Depth Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods showsPrec :: Int -> Depth -> ShowS Source # show :: Depth -> String Source # showList :: [Depth] -> ShowS Source #
Eq Depth Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods (==) :: Depth -> Depth -> Bool Source # (/=) :: Depth -> Depth -> Bool Source #
Ord Depth Source # |
Instance details Defined in Language.Futhark.Interpreter.AD Methods compare :: Depth -> Depth -> Ordering Source # (<) :: Depth -> Depth -> Bool Source # (<=) :: Depth -> Depth -> Bool Source # (>) :: Depth -> Depth -> Bool Source # (>=) :: Depth -> Depth -> Bool Source # max :: Depth -> Depth -> Depth Source # min :: Depth -> Depth -> Depth Source #

doOp :: Op -> [ADValue] -> Counter -> Either String (ADValue, Counter) Source #

addFor :: PrimType -> BinOp Source #

tapePrimal :: Tape -> ADValue Source #

Returns the primal value of a Tape.

primitive :: ADValue -> PrimValue Source #

varPrimal :: ADVariable -> PrimValue Source #

deriveTape :: Tape -> ADValue -> Counter -> Either String (Map Counter ADValue, Counter) Source #

This calculates every partial derivative of a `Tape`. The result is a map of the partial derivatives, each key corresponding to the ID of a free variable (see TapeID).

unionWithM :: (Monad m, Ord k) => (a -> a -> m a) -> Map k a -> Map k a -> m (Map k a) Source #

unionsWithM :: (Foldable f, Monad m, Ord k) => (a -> a -> m a) -> f (Map k a) -> m (Map k a) Source #