Skip to content

Commit 8fe1dd1

Browse files
authored
docs: specify complex number support and same type preparation (#651)
1 parent 19ec778 commit 8fe1dd1

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

DifferentiationInterface/docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ makedocs(;
3030
"explanation/operators.md",
3131
"explanation/backends.md",
3232
"explanation/advanced.md",
33+
"explanation/faq.md",
3334
],
3435
"api.md",
3536
"dev_guide.md",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# FAQ
2+
3+
## Complex numbers
4+
5+
At the moment, complex numbers are only handled by a few AD backends, sometimes using different conventions.
6+
As a result, DifferentiationInterface is only tested on real numbers and complex number support is not part of its API guarantees.

DifferentiationInterface/docs/src/explanation/operators.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,34 @@ op(f, prep, backend, x, [t]) # fast because it skips preparation
120120

121121
### Reusing preparation
122122

123-
Deciding whether it is safe to reuse the results of preparation is not easy.
124-
Here are the general rules that we strive to implement:
123+
It is not always safe to reuse the results of preparation.
124+
For different-point preparation, the output `prep` of
125125

126-
For different-point preparation, the output `prep` of `prepare_op(f, b, x, [t])` can be reused in `op(f, prep, b, other_x, [other_t])`, provided that:
126+
```julia
127+
prepare_op(f, [y], backend, x, [t, contexts...])
128+
```
129+
130+
can be reused in subsequent calls to
131+
132+
```julia
133+
op(f, prep, [other_y], backend, other_x, [other_t, other_contexts...])
134+
```
135+
136+
provided that the following conditions all hold:
137+
138+
- `f` and `backend` remain the same
139+
- `other_x` has the same type and size as `x`
140+
- `other_y` has the same type and size as `y`
141+
- `other_t` has the same type and size as `t`
142+
- all the elements of `other_contexts` have the same type and size as the corresponding elements of `contexts`
127143

128-
- the inputs `x` and `other_x` have the same types and sizes
129-
- the tangents in `t` and `other_t` have the same types and sizes
144+
For same-point preparation, the same rules hold with two modifications:
130145

131-
For same-point preparation, the output `prep` of `prepare_op_same_point(f, b, x, [t])` can be reused in `op(f, prep, b, x, other_t)`, provided that:
146+
- `other_x` must be _equal_ to `x`
147+
- any element of `other_contexts` with type `Constant` must be _equal_ to the corresponding element of `contexts`
132148

133-
- the input `x` remains exactly the same (as well as any [`Constant`](@ref) context)
134-
- the tangents in `t` and `other_t` have the same types and sizes
149+
!!! danger
150+
Reusing preparation with different types or sizes may work with some backends and error with others, so it is not allowed by the API of DifferentiationInterface.
135151

136152
!!! warning
137153
These rules hold for the majority of backends, but there are some exceptions.

0 commit comments

Comments
 (0)