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: DifferentiationInterface/docs/src/overview.md
+19-9Lines changed: 19 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,13 +47,16 @@ Several variants of each operator are defined:
47
47
In order to ensure symmetry between one-argument functions `f(x) = y` and two-argument functions `f!(y, x) = nothing`, we define the same operators for both cases.
|`f!(y, x)`|`operator(f!, y, backend, x, ...)`|`operator!(f!, y, result, backend, x, ...)`|
54
54
55
55
!!! warning
56
-
Every variant of the operator will mutate `y` when applied to a two-argument function `f!(y, x) = nothing`, even if it does not have a `!` in its name.
56
+
Our mutation convention is that all positional arguments between `f`/`f!` and `backend` are mutated (the `extras` as well, see below).
57
+
This convention holds regardless of the bang `!` in the operator name, because we assume that a user passing a two-argument function `f!(y, x)` anticipates mutation anyway.
58
+
59
+
Still, better be careful with two-argument functions, because every variant of the operator will mutate `y`... even if it does not have a `!` in its name (see the bottom left cell in the table).
57
60
58
61
## Preparation
59
62
@@ -71,14 +74,21 @@ This is a backend-specific procedure, but we expose a common syntax to achieve i
71
74
|`pullback`|[`prepare_pullback`](@ref)|
72
75
|`hvp`|[`prepare_hvp`](@ref)|
73
76
74
-
If you run `prepare_operator(backend, f, x, [seed])`, it will create an object called `extras` containing the necessary information to speed up `operator` and its variants.
77
+
Unsurprisingly, preparation syntax depends on the number of arguments:
|`f!(y, x)`|`prepare_operator(f!, y, backend, x, ...)`|
83
+
84
+
The preparation `prepare_operator(f, backend, x)` will create an object called `extras` containing the necessary information to speed up `operator` and its variants.
75
85
This information is specific to `backend` and `f`, as well as the _type and size_ of the input `x` and the _control flow_ within the function, but it should work with different _values_ of `x`.
76
86
77
-
You can then call `operator(backend, f, x2, extras)`, which should be faster than `operator(f, backend, x2)`.
87
+
You can then call e.g. `operator(backend, f, x2, extras)`, which should be faster than `operator(f, backend, x2)`.
78
88
This is especially worth it if you plan to call `operator` several times in similar settings: you can think of it as a warm up.
79
89
80
90
!!! warning
81
-
The `extras` object is nearly always mutated, even if the operator does not have a `!` in its name.
91
+
The `extras` object is nearly always mutated when given to an operator, even when said operator does not have a bang`!` in its name.
82
92
83
93
### Second order
84
94
@@ -129,7 +139,7 @@ We make this available for all backends with the following operators:
129
139
### Non-standard types
130
140
131
141
The package is thoroughly tested with inputs and outputs of the following types: `Float64`, `Vector{Float64}` and `Matrix{Float64}`.
132
-
We also expect it to work on all kinds of `Number` and `AbstractArray` variables.
142
+
We also expect it to work on most kinds of `Number` and `AbstractArray` variables.
133
143
Beyond that, you are in uncharted territory.
134
144
We voluntarily keep the type annotations minimal, so that passing more complex objects or custom structs _might work with some backends_, but we make no guarantees about that.
Copy file name to clipboardExpand all lines: DifferentiationInterface/docs/src/tutorial.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,10 +63,12 @@ Some backends get a speed boost from this trick.
63
63
64
64
```@repl tuto
65
65
grad = zero(x)
66
-
grad = gradient!(f, grad, backend, x)
66
+
gradient!(f, grad, backend, x);
67
+
grad
67
68
```
68
69
69
-
Note the double exclamation mark, which is a convention telling you that `grad`_may or may not_ be overwritten, but will be returned either way (see [this section](@ref Variants) for more details).
70
+
The bang indicates that one of the arguments of `gradient!` might be mutated.
71
+
More precisely, our convention is that _every positional argument between the function and the backend is mutated (and the `extras` too, see below)_.
Copy file name to clipboardExpand all lines: DifferentiationInterface/ext/DifferentiationInterfaceChainRulesCoreExt/DifferentiationInterfaceChainRulesCoreExt.jl
Copy file name to clipboardExpand all lines: DifferentiationInterface/ext/DifferentiationInterfaceDiffractorExt/DifferentiationInterfaceDiffractorExt.jl
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ using DifferentiationInterface: NoPushforwardExtras
6
6
using Diffractor: DiffractorRuleConfig, TaylorTangentIndex, ZeroBundle, bundle, ∂☆
Copy file name to clipboardExpand all lines: DifferentiationInterface/ext/DifferentiationInterfaceFastDifferentiationExt/DifferentiationInterfaceFastDifferentiationExt.jl
Copy file name to clipboardExpand all lines: DifferentiationInterface/ext/DifferentiationInterfaceFiniteDifferencesExt/DifferentiationInterfaceFiniteDifferencesExt.jl
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ using FiniteDifferences: FiniteDifferences, grad, jacobian, jvp, j′vp
0 commit comments