Tangent types
The values that come back from pullbacks or pushforwards are not always the same type as the input/outputs of the primal function. They are tangents, which correspond roughly to something able to represent the difference between two values of the primal types. A tangent might be such a regular type, like a Number
, or a Matrix
, matching to the original type; or it might be one of the AbstractTangent
subtypes.
Tangents support a number of operations. Most importantly: +
and *
, which let them act as mathematical objects.
The most important AbstractTangent
s when getting started are the ones about avoiding work:
Thunk
: this is a deferred computation. A thunk is a word for a zero argument closure. A computation wrapped in a@thunk
doesn't get evaluated untilunthunk
is called on the thunk.unthunk
is a no-op on non-thunked inputs.ZeroTangent
: It is a special representation of0
. It does great things around avoiding expandingThunks
in addition.
Other AbstractTangent
s:
Tangent{P}
: this is the tangent for tuples and structs. Use it like aTuple
orNamedTuple
. The type parameterP
is for the primal type.NoTangent
: Zero-like, represents that the operation on this input is not differentiable. Its primal type is normallyInteger
orBool
.InplaceableThunk
: it is like aThunk
but it can do in-placeadd!
.