You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rule_author/tangents.md
+17-6
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,23 @@ or it might be one of the [`AbstractTangent`](@ref ChainRulesCore.AbstractTangen
8
8
Tangents support a number of operations.
9
9
Most importantly: `+` and `*`, which let them act as mathematical objects.
10
10
11
-
The most important `AbstractTangent`s when getting started are the ones about avoiding work:
11
+
To be more formal they support operations which let them act as a vector space.
12
12
13
-
-[`Thunk`](@ref): this is a deferred computation. A thunk is a [word for a zero argument closure](https://en.wikipedia.org/wiki/Thunk). A computation wrapped in a `@thunk` doesn't get evaluated until [`unthunk`](@ref) is called on the thunk. `unthunk` is a no-op on non-thunked inputs.
14
-
-[`ZeroTangent`](@ref): It is a special representation of `0`. It does great things around avoiding expanding `Thunks` in addition.
13
+
## Operations on a tangent type
14
+
Any tangent type must support:
15
+
-`zero` which returns an additive identity for that type (though it can just return `ZeroTangent()` (see below))
16
+
-`+` for addition between two tangents of this primal, returning another tangent of this primal. This allows gradient accumulation.
17
+
-`*` for multiplication (scaling) by a scalar.
18
+
-`+` between a tangent and its primal type returning another tangent of the primal type -- differential geometers sometimes call this exponential map.
15
19
16
-
### Other `AbstractTangent`s:
17
-
-[`Tangent{P}`](@ref Tangent): this is the tangent for tuples and structs. Use it like a `Tuple` or `NamedTuple`. The type parameter `P` is for the primal type.
20
+
Further they often support other linear operators for convenience in writing rules.
21
+
22
+
## The subtypes of AbstractTangent
23
+
24
+
Not all tangents need to subtype the AbstractTangent type -- infact most don't: most are just numbers or arrays -- but ChainRulesCore does provide a number of special tangent types that can be very useful.
25
+
26
+
-[`ZeroTangent`](@ref): It is a special representation of `0`. It does great things around avoiding expanding `Thunks` in addition.
18
27
-[`NoTangent`](@ref): Zero-like, represents that the operation on this input is not differentiable. Its primal type is normally `Integer` or `Bool`.
19
-
-[`InplaceableThunk`](@ref): it is like a `Thunk` but it can do in-place `add!`.
28
+
-[`Tangent{P}`](@ref Tangent): this is the tangent for tuples and structs. Use it like a `Tuple` or `NamedTuple`. The type parameter `P` is for the primal type.
29
+
-[`Thunk`](@ref): this is a deferred computation. A thunk is a [word for a zero argument closure](https://en.wikipedia.org/wiki/Thunk). A computation wrapped in a `@thunk` doesn't get evaluated until [`unthunk`](@ref) is called on the thunk. `unthunk` is a no-op on non-thunked inputs.
30
+
-[`InplaceableThunk`](@ref): it is like a `Thunk` but it can do in-place `add!` which allows for avoiding allocation during gradient accumulation.
0 commit comments