Skip to content

Commit 1bbe185

Browse files
amontoisontmigot
andauthored
Apply suggestions from code review
Co-authored-by: Tangi Migot <[email protected]>
1 parent d508712 commit 1bbe185

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

docs/src/sparse.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ The `:direct` coloring mode is numerically more stable and may be preferable for
5050

5151
## Extracting sparsity patterns
5252

53-
`ADNLPModels.jl` provides the function `get_sparsity_pattern` to retrieve the sparsity patterns of the Jacobian or Hessian from a model.
54-
55-
```@docs
56-
get_sparsity_pattern
57-
```
53+
`ADNLPModels.jl` provides the function [`get_sparsity_pattern`](@ref) to retrieve the sparsity patterns of the Jacobian or Hessian from a model.
5854

5955
```@example ex3
6056
using SparseArrays, ADNLPModels, NLPModels
@@ -100,7 +96,7 @@ ncon = 5
10096
10197
f(x) = sum((x[i] - i)^2 for i = 1:nvar) + x[nvar] * sum(x[j] for j = 1:nvar-1)
10298
103-
H = SparseMatrixCSC{Bool,Int}(
99+
H = SparseMatrixCSC{Bool, Int}(
104100
[ 1 0 0 0 0 0 0 0 0 1 ;
105101
0 1 0 0 0 0 0 0 0 1 ;
106102
0 0 1 0 0 0 0 0 0 1 ;
@@ -122,7 +118,7 @@ function c!(cx, x)
122118
return cx
123119
end
124120
125-
J = SparseMatrixCSC{Bool,Int}(
121+
J = SparseMatrixCSC{Bool, Int}(
126122
[ 1 1 0 0 0 0 0 0 0 0 ;
127123
1 1 1 0 0 0 0 0 0 0 ;
128124
0 1 1 1 0 0 0 0 0 0 ;
@@ -145,7 +141,6 @@ nlp = ADNLPModel!(f, x0, lvar, uvar, c!, lcon, ucon, jacobian_backend=J_backend,
145141

146142
The section ["providing the sparsity pattern for sparse derivatives"](@ref sparsity-pattern) illustrates this feature with a more advanced application.
147143

148-
149144
### Acknowledgements
150145

151146
The package [`SparseConnectivityTracer.jl`](https://github.com/adrhill/SparseConnectivityTracer.jl) is used to compute the sparsity pattern of Jacobians and Hessians.

src/sparsity_pattern.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ function get_sparsity_pattern(model::ADModel, derivate::Symbol)
7777
if (derivate != :jacobian) && (derivate != :hessian)
7878
if model isa AbstractADNLPModel
7979
error("The only supported sparse derivates for an AbstractADNLPModel are `:jacobian` and `:hessian`.")
80-
elseif (derivate != :jacobian_residual) && (derivate != :hessian_resiual)
80+
elseif (model isa AbstractADNLSModel) && (derivate != :jacobian_residual) && (derivate != :hessian_resiual)
81+
# ...
82+
else
83+
# ERROR
8184
error("The only supported sparse derivates for an AbstractADNLSModel are `:jacobian`, `:jacobian_residual`, `:hessian` and `:hessian_resiual`.")
8285
end
8386
end

0 commit comments

Comments
 (0)