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/faq.md
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,29 +12,32 @@ To differentiate through an `ImplicitFunction`, the following backends are suppo
12
12
13
13
By default, the conditions are differentiated using the same "outer" backend that is trying to differentiate the `ImplicitFunction`.
14
14
However, this can be switched to any other "inner" backend compatible with [DifferentiationInterface.jl](https://github.com/gdalle/DifferentiationInterface.jl) (i.e. a subtype of `ADTypes.AbstractADType`).
15
-
You can override the default with the `conditions_x_backend` and `conditions_y_backend` keyword arguments when constructing an `ImplicitFunction`.
16
15
17
16
## Input and output types
18
17
19
-
### Arrays
18
+
### Vectors
20
19
21
20
Functions that eat or spit out arbitrary vectors are supported, as long as the forward mapping _and_ conditions return vectors of the same size.
22
21
23
22
If you deal with small vectors (say, less than 100 elements), consider using [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) for increased performance.
24
23
24
+
### Arrays
25
+
26
+
Functions that eat or spit out matrices and higher-order tensors are not supported.
27
+
You can use `vec` and `reshape` for the conversion to and from vectors.
28
+
25
29
### Scalars
26
30
27
31
Functions that eat or spit out a single number are not supported.
28
32
The forward mapping _and_ conditions need vectors: instead of returning `val` you should return `[val]` (a 1-element `Vector`).
29
33
Or better yet, wrap it in a static vector: `SVector(val)`.
30
34
31
-
### Sparse vectors
35
+
### Sparse arrays
32
36
33
37
!!! danger "Danger"
34
-
Sparse vectors are not supported and might give incorrect values or `NaN`s!
38
+
Sparse arrays are not supported out of the box and might yield incorrect values!
35
39
36
-
With ForwardDiff.jl, differentiation of sparse vectors will often give wrong results due to [sparsity pattern cancellation](https://github.com/JuliaDiff/ForwardDiff.jl/issues/658).
37
-
That is why we do not test behavior for sparse inputs.
40
+
If your use case involves sparse arrays, it is best to differentiate with respect to the dense vector of values and only construct the sparse array inside of the `forward` and `conditions` functions.
Copy file name to clipboardExpand all lines: src/implicit_function.jl
+4-10Lines changed: 4 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
"""
2
2
KrylovLinearSolver
3
3
4
-
Callable object that can solve linear systems `As = b` and `AS = b` in the same way that `\`.
4
+
Callable object that can solve linear systems `As = b` and `AS = b` in the same way as the built-in `\\`.
5
5
Uses an iterative solver from [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl) under the hood.
6
6
7
7
# Note
@@ -81,7 +81,7 @@ The provided `linear_solver` objects needs to be callable, with two methods:
81
81
- `(A, b::AbstractVector) -> s::AbstractVector` such that `A * s = b`
82
82
- `(A, B::AbstractVector) -> S::AbstractMatrix` such that `A * S = B`
83
83
84
-
It can be either a direct solver (like `\`) or an iterative one (like [`KrylovLinearSolver`](@ref)).
84
+
It can be either a direct solver (like `\\`) or an iterative one (like [`KrylovLinearSolver`](@ref)).
85
85
Typically, direct solvers work best with dense Jacobians (`lazy = false`) while iterative solvers work best with operators (`lazy = true`).
86
86
87
87
# Condition backends
@@ -103,11 +103,7 @@ end
103
103
"""
104
104
ImplicitFunction{lazy}(
105
105
forward, conditions;
106
-
linear_solver=if lazy
107
-
KrylovLinearSolver()
108
-
else
109
-
\
110
-
end,
106
+
linear_solver=lazy ? KrylovLinearSolver() : \\,
111
107
conditions_x_backend=nothing,
112
108
conditions_x_backend=nothing,
113
109
)
@@ -138,9 +134,7 @@ end
138
134
conditions_x_backend=nothing,
139
135
)
140
136
141
-
Constructor for an [`ImplicitFunction`](@ref) which picks the `lazy` parameter automatically based on the `linear_solver`, using the following heuristic:
142
-
143
-
lazy = linear_solver != \
137
+
Constructor for an [`ImplicitFunction`](@ref) which picks the `lazy` parameter automatically based on the `linear_solver`, using the following heuristic: `lazy = linear_solver != \\`.
0 commit comments