Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ authors = ["Sophie Lequeu <slequeu@hotmail.com>", "Benoît Legat <benoit.legat@g

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

[compat]
Calculus = "0.5.2"
DataStructures = "0.18, 0.19"
ForwardDiff = "1"
JuMP = "1.29.4"
MathOptInterface = "1.40"
NaNMath = "1"
SparseArrays = "1.10"
SparseMatrixColorings = "0.4.26"
SpecialFunctions = "2.6.1"
julia = "1.10"
30 changes: 27 additions & 3 deletions src/ArrayDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,37 @@

module ArrayDiff

import SparseArrays
import SparseMatrixColorings as SMC
import ForwardDiff
import MathOptInterface as MOI
const Nonlinear = MOI.Nonlinear
import SparseArrays
import OrderedCollections: OrderedDict

struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end
"""
Mode(coloring_algorithm::SMC.GreedyColoringAlgorithm) <: AbstractAutomaticDifferentiation

Fork of `MOI.Nonlinear.SparseReverseMode` to add array support.
"""
struct Mode{C<:SMC.GreedyColoringAlgorithm} <:
MOI.Nonlinear.AbstractAutomaticDifferentiation
coloring_algorithm::C
end

function Mode()
return Mode(SMC.GreedyColoringAlgorithm(; decompression = :substitution))
end

function MOI.Nonlinear.Evaluator(
model::MOI.Nonlinear.Model,
mode::Mode,
ordered_variables::Vector{MOI.VariableIndex},
)
return MOI.Nonlinear.Evaluator(
model,
NLPEvaluator(model, ordered_variables, mode.coloring_algorithm),
)
end

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

include("Coloring/Coloring.jl")
include("coloring.jl")
include("graph_tools.jl")
include("sizes.jl")
include("univariate_expressions.jl")
Expand Down
Loading
Loading