Skip to content

Commit fbb4936

Browse files
authored
Merge pull request #573 from JuliaDiff/ox/tandoc
Improve documentation of tangent types
2 parents d39a044 + 4d4df78 commit fbb4936

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

docs/src/rule_author/tangents.md

+17-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ or it might be one of the [`AbstractTangent`](@ref ChainRulesCore.AbstractTangen
88
Tangents support a number of operations.
99
Most importantly: `+` and `*`, which let them act as mathematical objects.
1010

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.
1212

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.
1519

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.
1827
- [`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

Comments
 (0)