Skip to content

Commit 36d43b8

Browse files
committed
Replace Coloring by SparseMatrixColoring
1 parent d5df492 commit 36d43b8

14 files changed

Lines changed: 325 additions & 782 deletions

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ jobs:
2525
version: ${{ matrix.version }}
2626
arch: ${{ matrix.arch }}
2727
- uses: julia-actions/cache@v1
28+
- name: MOI
29+
shell: julia --project=@. {0}
30+
run: |
31+
using Pkg
32+
Pkg.add([
33+
PackageSpec(url="https://github.com/blegat/SparseMatrixColorings.jl/", rev="abstractsparse"),
34+
])
2835
- uses: julia-actions/julia-buildpkg@v1
2936
- uses: julia-actions/julia-runtest@v1
3037
with:

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ authors = ["Sophie Lequeu <slequeu@hotmail.com>", "Benoît Legat <benoit.legat@g
55

66
[deps]
77
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
8-
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
98
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
109
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1110
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
1211
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1312
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
13+
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
1414
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1515

1616
[compat]
1717
Calculus = "0.5.2"
18-
DataStructures = "0.18, 0.19"
1918
ForwardDiff = "1"
2019
MathOptInterface = "1.40"
2120
NaNMath = "1"
2221
SparseArrays = "1.10"
22+
SparseMatrixColorings = "0.4"
2323
SpecialFunctions = "2.6.1"
2424
julia = "1.10"

src/ArrayDiff.jl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@
66

77
module ArrayDiff
88

9+
import SparseArrays
10+
import SparseMatrixColorings as SMC
911
import ForwardDiff
1012
import MathOptInterface as MOI
1113
const Nonlinear = MOI.Nonlinear
12-
import SparseArrays
1314
import OrderedCollections: OrderedDict
1415

15-
struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end
16+
"""
17+
Mode(coloring_algorithm::SMC.GreedyColoringAlgorithm) <: AbstractAutomaticDifferentiation
18+
19+
Fork of `MOI.Nonlinear.SparseReverseMode` to add array support.
20+
"""
21+
struct Mode{C<:SMC.GreedyColoringAlgorithm} <:
22+
MOI.Nonlinear.AbstractAutomaticDifferentiation
23+
coloring_algorithm::C
24+
end
25+
26+
function Mode()
27+
return Mode(SMC.GreedyColoringAlgorithm(; decompression = :substitution))
28+
end
29+
30+
function MOI.Nonlinear.Evaluator(
31+
model::MOI.Nonlinear.Model,
32+
mode::Mode,
33+
ordered_variables::Vector{MOI.VariableIndex},
34+
)
35+
return MOI.Nonlinear.Evaluator(
36+
model,
37+
NLPEvaluator(model, ordered_variables, mode.coloring_algorithm),
38+
)
39+
end
1640

1741
# Override basic math functions to return NaN instead of throwing errors.
1842
# This is what NLP solvers expect, and sometimes the results aren't needed
@@ -33,7 +57,7 @@ import NaNMath:
3357
pow,
3458
sqrt
3559

36-
include("Coloring/Coloring.jl")
60+
include("coloring.jl")
3761
include("graph_tools.jl")
3862
include("sizes.jl")
3963
include("univariate_expressions.jl")

0 commit comments

Comments
 (0)