Skip to content

Commit

Permalink
Improve nnz_colors
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jul 18, 2024
1 parent b98bda8 commit 22e0e49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ADNLPModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using LinearAlgebra, SparseArrays
# external
using ADTypes: ADTypes, AbstractColoringAlgorithm, AbstractSparsityDetector
using SparseConnectivityTracer: TracerSparsityDetector
using SparseMatrixColorings: GreedyColoringAlgorithm
using SparseMatrixColorings: GreedyColoringAlgorithm, symmetric_coloring_detailed
using ForwardDiff, ReverseDiff

# JSO
Expand Down
4 changes: 2 additions & 2 deletions src/sparse_hessian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function SparseADHessian(
T = eltype(S)
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)

colors, star_set = SparseMatrixColorings.symmetric_coloring_detailed(H, coloring)
colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)

d = BitVector(undef, nvar)
Expand Down Expand Up @@ -118,7 +118,7 @@ function SparseReverseADHessian(
) where {T}
H = compute_hessian_sparsity(f, nvar, c!, ncon, detector = detector)

colors, star_set = SparseMatrixColorings.symmetric_coloring_detailed(H, coloring)
colors, star_set = symmetric_coloring_detailed(H, coloring)
ncolors = maximum(colors)

d = BitVector(undef, nvar)
Expand Down
8 changes: 6 additions & 2 deletions src/sparsity_pattern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ function nnz_colors(trilH, star_set, colors, ncolors)
for k in trilH.colptr[j]:trilH.colptr[j+1]-1
i = trilH.rowval[k]

star_id = star[(i, j)]
h = hub[star_id]
if i == j
h = i
else
star_id = star[(j, i)]
h = hub[star_id]
end

# pick arbitrary hub
(h == 0) && (h = i)
Expand Down

0 comments on commit 22e0e49

Please sign in to comment.