Skip to content

Commit f9304b3

Browse files
authored
Replace the uses of "differential" with "tangent" where appropriate (#513)
1 parent 4d27d7e commit f9304b3

18 files changed

+115
-117
lines changed

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ makedocs(;
5050
"Introduction" => "index.md",
5151
"How to use ChainRules as a rule author" => [
5252
"Introduction" => "rule_author/intro.md",
53-
"Tangent types" => "rule_author/differentials.md",
53+
"Tangent types" => "rule_author/tangents.md",
5454
#"`frule` and `rrule`" => "rule_author/rules.md", # TODO: a complete example
5555
"Writing good rules" => "rule_author/writing_good_rules.md",
5656
"Testing your rules" => "rule_author/testing.md",
@@ -77,7 +77,7 @@ makedocs(;
7777
],
7878
"Design" => [
7979
"Changing the Primal" => "design/changing_the_primal.md",
80-
"Many Tangent Types" => "design/many_differentials.md",
80+
"Many Tangent Types" => "design/many_tangents.md",
8181
],
8282
"Videos" => "videos.md",
8383
"FAQ" => "FAQ.md",

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Pages = ["rule_definition_tools.jl"]
1414
Private = false
1515
```
1616

17-
## Differentials
17+
## Tangent Types
1818
```@autodocs
1919
Modules = [ChainRulesCore]
2020
Pages = [

docs/src/design/many_differentials.md renamed to docs/src/design/many_tangents.md

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

docs/src/rule_author/converting_zygoterules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ See docs on [Constructors](@ref).
4444
## Include the derivative with respect to the function object itself
4545
The `ZygoteRules.@adjoint` macro automagically[^1] inserts an extra `nothing` in the return for the function it generates to represent the derivative of output with respect to the function object.
4646
ChainRules as a philosophy avoids magic as much as possible, and thus require you to return it explicitly.
47-
If it is a plain function (like `typeof(sin)`), then the differential will be [`NoTangent`](@ref).
47+
If it is a plain function (like `typeof(sin)`), then the tangent will be [`NoTangent`](@ref).
4848

4949

5050
[^1]: unless you write it in functor form (i.e. `@adjoint (f::MyType)(args...)=...`), in that case like for `rrule` you need to include it explictly.

docs/src/rule_author/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This section of the docs will tell you everything you need to know about writing rules for your package.
44

5-
It will help with understanding differential types, the anatomy of the `frule` and
5+
It will help with understanding tangent types, the anatomy of the `frule` and
66
the `rrule`, and provide tips on writing good rules, as well as how to test them easily
77
using finite differences.
88

docs/src/rule_author/superpowers/gradient_accumulation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ end
1919
The AD software must transform that into something which repeatedly sums up the gradient of each part:
2020
`X̄ = ā + b̄`.
2121

22-
This requires that all differential types `D` must implement `+`: `+(::D, ::D)::D`.
22+
This requires that all tangent types `D` must implement `+`: `+(::D, ::D)::D`.
2323

2424
We can note that in this particular case `` and `` will both be arrays.
2525
This operation (`X̄ = ā + b̄`) will allocate one array to hold `ā`, another one to hold ``, and a third one to hold `ā + b̄`.
@@ -47,7 +47,7 @@ AD systems can generate `add!!` instead of `+` when accumulating gradient to tak
4747

4848
### Inplaceable Thunks (`InplaceableThunks`) avoid allocating values in the first place.
4949
We got down to two allocations from using [`add!!`](@ref), but can we do better?
50-
We can think of having a differential type which acts on a partially accumulated result, to mutate it to contain its current value plus the partial derivative being accumulated.
50+
We can think of having a tangent type which acts on a partially accumulated result, to mutate it to contain its current value plus the partial derivative being accumulated.
5151
Rather than having an actual computed value, we can just have a thing that will act on a value to perform the addition.
5252
Let's illustrate it with our example.
5353

@@ -79,9 +79,9 @@ The `val` field use a plain [`Thunk`](@ref) to avoid the computation (and thus a
7979
!!! note "Do we need both representations?"
8080
Right now every [`InplaceableThunk`](@ref) has two fields that need to be specified.
8181
The value form (represented as a the [`Thunk`](@ref) typed field), and the action form (represented as the `add!` field).
82-
It is possible in a future version of ChainRulesCore.jl we will work out a clever way to find the zero differential for arbitrary primal values.
83-
Given that, we could always just determine the value form from `inplaceable.add!(zero_differential(primal))`.
84-
There are some technical difficulties in finding the zero differentials, but this may be solved at some point.
82+
It is possible in a future version of ChainRulesCore.jl we will work out a clever way to find the zero tangent for arbitrary primal values.
83+
Given that, we could always just determine the value form from `inplaceable.add!(zero_tangent(primal))`.
84+
There are some technical difficulties in finding the zero tangents, but this may be solved at some point.
8585

8686

8787
The `+` operation on `InplaceableThunk`s is overloaded to [`unthunk`](@ref) that `val` field to get the value form.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# [Tangent types](@id tangents)
22

33
The values that come back from pullbacks or pushforwards are not always the same type as the input/outputs of the primal function.
4-
They are differentials, which correspond roughly to something able to represent the difference between two values of the primal types.
5-
A differential might be such a regular type, like a `Number`, or a `Matrix`, matching to the original type;
4+
They are tangents, which correspond roughly to something able to represent the difference between two values of the primal types.
5+
A tangent might be such a regular type, like a `Number`, or a `Matrix`, matching to the original type;
66
or it might be one of the [`AbstractTangent`](@ref ChainRulesCore.AbstractTangent) subtypes.
77

8-
Differentials support a number of operations.
8+
Tangents support a number of operations.
99
Most importantly: `+` and `*`, which let them act as mathematical objects.
1010

1111
The most important `AbstractTangent`s when getting started are the ones about avoiding work:
@@ -14,6 +14,6 @@ The most important `AbstractTangent`s when getting started are the ones about av
1414
- [`ZeroTangent`](@ref): It is a special representation of `0`. It does great things around avoiding expanding `Thunks` in addition.
1515

1616
### Other `AbstractTangent`s:
17-
- [`Tangent{P}`](@ref Tangent): this is the differential for tuples and structs. Use it like a `Tuple` or `NamedTuple`. The type parameter `P` is for the primal type.
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.
1818
- [`NoTangent`](@ref): Zero-like, represents that the operation on this input is not differentiable. Its primal type is normally `Integer` or `Bool`.
1919
- [`InplaceableThunk`](@ref): it is like a `Thunk` but it can do in-place `add!`.

docs/src/rule_author/writing_good_rules.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This woull be solved once [JuliaLang/julia#38241](https://github.com/JuliaLang/j
4444

4545
## Use `Thunk`s appropriately
4646

47-
If work is only required for one of the returned differentials, then it should be wrapped in a `@thunk` (potentially using a `begin`-`end` block).
47+
If work is only required for one of the returned tangents, then it should be wrapped in a `@thunk` (potentially using a `begin`-`end` block).
4848

4949
If there are multiple return values, their computation should almost always be wrapped in a `@thunk`.
5050

@@ -169,16 +169,16 @@ For example, if a primal type `P` overloads subtraction (`-(::P,::P)`) then that
169169
Common cases for types that represent a [vector-space](https://en.wikipedia.org/wiki/Vector_space) (e.g. `Float64`, `Array{Float64}`) is that the natural tangent type is the same as the primal type.
170170
However, this is not always the case.
171171
For example for a [`PDiagMat`](https://github.com/JuliaStats/PDMats.jl) a natural tangent is `Diagonal` since there is no requirement that a positive definite diagonal matrix has a positive definite tangent.
172-
Another example is for a `DateTime`, any `Period` subtype, such as `Millisecond` or `Nanosecond` is a natural differential.
172+
Another example is for a `DateTime`, any `Period` subtype, such as `Millisecond` or `Nanosecond` is a natural tangent.
173173
There are often many different natural tangent types for a given primal type.
174174
However, they are generally closely related and duck-type the same.
175175
For example, for most `AbstractArray` subtypes, most other `AbstractArray`s (of right size and element type) can be considered as natural tangent types.
176176

177177
Not all types have natural tangent types.
178-
For example there is no natural differential for a `Tuple`.
178+
For example there is no natural tangent for a `Tuple`.
179179
It is not a `Tuple` since that doesn't have any method for `+`.
180180
Similar is true for many `struct`s.
181-
For those cases there is only a structural differential.
181+
For those cases there is only a structural tangent.
182182

183183
### Structural tangents
184184

@@ -216,10 +216,10 @@ In this sense they wrap either a natural or structural tangent.
216216

217217
## Use `@not_implemented` appropriately
218218

219-
You can use [`@not_implemented`](@ref) to mark missing differentials.
220-
This is helpful if the function has multiple inputs or outputs, and you have worked out analytically and implemented some but not all differentials.
219+
You can use [`@not_implemented`](@ref) to mark missing tangents.
220+
This is helpful if the function has multiple inputs or outputs, and you have worked out analytically and implemented some but not all tangents.
221221

222-
It is recommended to include a link to a GitHub issue about the missing differential in the debugging information:
222+
It is recommended to include a link to a GitHub issue about the missing tangent in the debugging information:
223223
```julia
224224
@not_implemented(
225225
"""
@@ -229,9 +229,9 @@ It is recommended to include a link to a GitHub issue about the missing differen
229229
)
230230
```
231231

232-
Do not use `@not_implemented` if the differential does not exist mathematically (use `NoTangent()` instead).
232+
Do not use `@not_implemented` if the tangent does not exist mathematically (use `NoTangent()` instead).
233233

234-
Note: [ChainRulesTestUtils.jl](https://github.com/JuliaDiff/ChainRulesTestUtils.jl) marks `@not_implemented` differentials as "test broken".
234+
Note: [ChainRulesTestUtils.jl](https://github.com/JuliaDiff/ChainRulesTestUtils.jl) marks `@not_implemented` tangents as "test broken".
235235

236236
## Use rule definition tools
237237

src/ChainRulesCore.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export RuleConfig, HasReverseMode, NoReverseMode, HasForwardsMode, NoForwardsMod
1111
export frule_via_ad, rrule_via_ad
1212
# definition helper macros
1313
export @non_differentiable, @opt_out, @scalar_rule, @thunk, @not_implemented
14-
export ProjectTo, canonicalize, unthunk # differential operations
14+
export ProjectTo, canonicalize, unthunk # tangent operations
1515
export add!! # gradient accumulation operations
1616
export ignore_derivatives, @ignore_derivatives
17-
# differentials
17+
# tangents
1818
export Tangent, NoTangent, InplaceableThunk, Thunk, ZeroTangent, AbstractZero, AbstractThunk
1919

2020
include("compat.jl")

src/accumulation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
4040
Returns true if `x` is suitable for for storing inplace accumulation of gradients.
4141
For arrays this boils down `x .= y` if will work to mutate `x`, if `y` is an appropriate
42-
differential.
42+
tangent.
4343
Wrapper array types do not need to overload this if they overload `Base.parent`, and are
4444
`is_inplaceable_destination` if and only if their parent array is.
4545
Other types should overload this, as it defaults to `false`.

0 commit comments

Comments
 (0)