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
@@ -31,9 +31,9 @@ Or better yet, wrap it in a static vector: `SVector(val)`.
31
31
### Sparse arrays
32
32
33
33
!!! danger "Danger"
34
-
Sparse arrays are not officially supported and might give incorrect values or `NaN`s!
34
+
Sparse arrays are not supported and might give incorrect values or `NaN`s!
35
35
36
-
With ForwardDiff.jl, differentiation of sparse arrays will always give wrong results due to [sparsity pattern cancellation](https://github.com/JuliaDiff/ForwardDiff.jl/issues/658).
36
+
With ForwardDiff.jl, differentiation of sparse arrays will often give wrong results due to [sparsity pattern cancellation](https://github.com/JuliaDiff/ForwardDiff.jl/issues/658).
37
37
That is why we do not test behavior for sparse inputs.
38
38
39
39
## Number of inputs and outputs
@@ -92,6 +92,21 @@ This is mainly useful when the solution procedure creates objects such as Jacobi
92
92
In that case, you may want to write the conditions differentiation rules yourself.
93
93
A more advanced application is given by [DifferentiableFrankWolfe.jl](https://github.com/gdalle/DifferentiableFrankWolfe.jl).
94
94
95
+
## Linear system
96
+
97
+
### Lazy or dense
98
+
99
+
Usually, dense Jacobians are more efficient in small dimension, while lazy operators become necessary in high dimension.
100
+
This choice is made via the `lazy` type parameter of [`ImplicitFunction`](@ref), with `lazy = true` being the default.
101
+
102
+
### Picking a solver
103
+
104
+
The right linear solver to use depends on the Jacobian representation.
105
+
You can usually stick to the default settings:
106
+
107
+
- the direct solver `\` for dense Jacobians
108
+
- an iterative solver from [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl) for lazy operators
Copy file name to clipboardExpand all lines: src/implicit_function.jl
+64-17Lines changed: 64 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ function (::DefaultLinearSolver)(A, B::AbstractMatrix)
14
14
end
15
15
16
16
"""
17
-
ImplicitFunction
17
+
ImplicitFunction{lazy}
18
18
19
19
Wrapper for an implicit function defined by a forward mapping `y` and a set of conditions `c`.
20
20
@@ -27,47 +27,94 @@ This requires solving a linear system `A * J = -B` where `A = ∂c/∂y`, `B =
27
27
28
28
# Fields
29
29
30
-
- `forward`: a callable, does not need to be compatible with automatic differentiation
31
-
- `conditions`: a callable, must be compatible with automatic differentiation
32
-
- `linear_solver`: a callable with two methods:
33
-
- `(A, b::AbstractVector) -> s::AbstractVector` such that `A * s = b`
34
-
- `(A, B::AbstractVector) -> S::AbstractMatrix` such that `A * S = B`
35
-
- `conditions_x_backend`: either `nothing` or an object subtyping `AbstractADType` from [ADTypes.jl](https://github.com/SciML/ADTypes.jl), defines how the conditions will be differentiated with respect to the first argument `x`
36
-
- `conditions_y_backend`: same for the second argument `y`
30
+
- `forward`: a callable computing `y(x)`, does not need to be compatible with automatic differentiation
31
+
- `conditions`: a callable computing `c(x, y)`, must be compatible with automatic differentiation
32
+
- `linear_solver`: a callable to solve the linear system `A * J = -B`
33
+
- `conditions_x_backend`: defines how the conditions will be differentiated with respect to the first argument `x`
34
+
- `conditions_y_backend`: defines how the conditions will be differentiated with respect to the second argument `y`
35
+
36
+
# Type parameters
37
+
38
+
- `lazy`: whether to use a `LinearOperator` from [LinearOperators.jl](https://github.com/JuliaSmoothOptimizers/LinearOperators.jl) (`lazy = true`) or a dense Jacobian matrix (`lazy = false`) for `A` and `B`
- `linear_solver`: the direct solver `\` for dense Jacobians, or an iterative solver from [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl) for lazy operators
56
+
- `conditions_x_backend = nothing`
57
+
- `conditions_y_backend = nothing`
58
+
59
+
# Function signatures
37
60
38
61
There are two possible signatures for `forward` and `conditions`, which must be consistent with one another:
0 commit comments