Skip to content

Commit

Permalink
🤖 Format .jl files
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jun 5, 2024
1 parent ed9756e commit 29b1d2d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function SparseADHessian(
kwargs...,
) where {S}
T = eltype(S)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector=detector)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)

colors = sparse_matrix_colors(H, alg)
ncolors = maximum(colors)
Expand Down Expand Up @@ -96,7 +96,7 @@ function SparseReverseADHessian(
detector::AbstractSparsityDetector = TracerSparsityDetector(),
kwargs...,
) where {T}
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector=detector)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)

colors = sparse_matrix_colors(H, alg)
ncolors = maximum(colors)
Expand Down
2 changes: 1 addition & 1 deletion src/sparse_jacobian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function SparseADJacobian(
kwargs...,
) where {T}
output = similar(x0, ncon)
J = compute_jacobian_sparsity(c!, output, x0, detector=detector)
J = compute_jacobian_sparsity(c!, output, x0, detector = detector)

colors = sparse_matrix_colors(J, alg)
ncolors = maximum(colors)
Expand Down
21 changes: 18 additions & 3 deletions src/sparsity_pattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ Return a sparse boolean matrix that represents the adjacency matrix of the Jacob
"""
function compute_jacobian_sparsity end

function compute_jacobian_sparsity(c, x0; detector::AbstractSparsityDetector=TracerSparsityDetector())
function compute_jacobian_sparsity(
c,
x0;
detector::AbstractSparsityDetector = TracerSparsityDetector(),
)
S = ADTypes.jacobian_sparsity(c, x0, detector)
return S
end

function compute_jacobian_sparsity(c!, cx, x0; detector::AbstractSparsityDetector=TracerSparsityDetector())
function compute_jacobian_sparsity(
c!,
cx,
x0;
detector::AbstractSparsityDetector = TracerSparsityDetector(),
)
S = ADTypes.jacobian_sparsity(c!, cx, x0, detector)
return S
end
Expand All @@ -21,7 +30,13 @@ end
Return a sparse boolean matrix that represents the adjacency matrix of the Hessian of f(x) + λᵀc(x).
"""
function compute_hessian_sparsity(f, nvar, c!, ncon; detector::AbstractSparsityDetector=TracerSparsityDetector())
function compute_hessian_sparsity(
f,
nvar,
c!,
ncon;
detector::AbstractSparsityDetector = TracerSparsityDetector(),
)
function lagrangian(x)
if ncon == 0
return f(x)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using ADNLPModels:
gradient, gradient!, jacobian, hessian, Jprod!, Jtprod!, directional_second_derivative, Hvprod!

@testset "Test sparsity pattern of Jacobian and Hessian" begin
f(x) = sum(x.^2)
f(x) = sum(x .^ 2)
c(x) = x
c!(cx, x) = copyto!(cx, x)
nvar, ncon = 2, 2
Expand Down
6 changes: 2 additions & 4 deletions test/sparse_hessian.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
list_sparse_hess_backend = (
(ADNLPModels.SparseADHessian, Dict()),
(ADNLPModels.ForwardDiffADHessian, Dict()),
)
list_sparse_hess_backend =
((ADNLPModels.SparseADHessian, Dict()), (ADNLPModels.ForwardDiffADHessian, Dict()))

dt = (Float32, Float64)

Expand Down

0 comments on commit 29b1d2d

Please sign in to comment.