ad-dualrev-th-0.1.0.0: Implementation of dual-numbers reverse AD for Haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Haskell.ReverseAD.TH

Synopsis

Reverse AD

reverseAD :: forall a b. (Typeable a, Typeable b) => Code Q (a -> b) -> Code Q (a -> (b, b -> a)) Source #

Use as follows:

> :t $$(reverseAD @_ @Double [|| \(x, y) -> x * y ||])
(Double, Double) -> (Double, Double -> (Double, Double))

The active scalar type is Double. Double values are differentiated; Float is currently unsupported.

Note that due to the GHC stage restriction, any data types used in a and b must be defined in a separate module that is then imported into the module where you use reverseAD. If you get a GHC panic about $tcFoo not being in scope (where Foo is your data type), this means that you violated this stage restriction. See GHC #21547.

reverseAD' Source #

Arguments

:: forall a b. Q Structure

Structure of a

-> Q Structure

Structure of b

-> Code Q (a -> b) 
-> Code Q (a -> (b, b -> a)) 

Same as reverseAD, but with user-supplied Structures.

Structure descriptions

data Structure Source #

The structure of a type, as used by the AD transformation. Use structureFromTypeable or structureFromType to construct a Structure.

Instances

Instances details
Show Structure Source # 
Instance details

Defined in Language.Haskell.ReverseAD.TH

NFData Structure Source # 
Instance details

Defined in Language.Haskell.ReverseAD.TH

Methods

rnf :: Structure -> () #

structureFromTypeable :: Typeable a => Proxy a -> Q Structure Source #

A TypeRep (which we can obtain from the Typeable constraint) can be used to construct a Type for the type a, on which we can then call structureFromType.

structureFromType :: Q Type -> Q Structure Source #

Analyse the Type and give a Structure that describes the type for use in reverseAD'.

Special methods

(|*|) :: a -> b -> (a, b) Source #

Parallel (strict) pair construction.

The definition of x |*| y is x `par` y `par` (x, y): x and y are evaluated in parallel. This also means that this pair constructor is, in a certain sense, strict.

In differentiation using reverseAD, this function is specially interpreted so that not only the forward pass, but also the reverse gradient pass runs in parallel.

Debug