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

Safe Haskell | Safe-Inferred
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 Int ADVariable
  - | Constant PrimValue
- data Tape
  - = TapeID Int ADValue
  - | TapeConst ADValue
  - | TapeOp Op [Tape] ADValue
- newtype VJPValue = VJPValue Tape
- data JVPValue = JVPValue ADValue ADValue
- doOp :: Op -> [ADValue] -> Maybe ADValue
- addFor :: PrimType -> BinOp
- tapePrimal :: Tape -> ADValue
- primitive :: ADValue -> PrimValue
- varPrimal :: ADVariable -> PrimValue
- deriveTape :: Tape -> ADValue -> Map Int ADValue

# 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 Int 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. TODO: make this a graph.

Constructors

TapeID Int 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] 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 #

doOp :: Op -> [ADValue] -> Maybe ADValue 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 -> Map Int ADValue 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).