-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDiff.jl
More file actions
64 lines (54 loc) · 1.43 KB
/
ArrayDiff.jl
File metadata and controls
64 lines (54 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
module ArrayDiff
import ForwardDiff
import MathOptInterface as MOI
const Nonlinear = MOI.Nonlinear
import SparseArrays
import OrderedCollections: OrderedDict
"""
Mode() <: AbstractAutomaticDifferentiation
Fork of `MOI.Nonlinear.SparseReverseMode` to add array support.
"""
struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end
function MOI.Nonlinear.Evaluator(
model::MOI.Nonlinear.Model,
::Mode,
ordered_variables::Vector{MOI.VariableIndex},
)
return MOI.Nonlinear.Evaluator(
model,
NLPEvaluator(model, ordered_variables),
)
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
# anyway, because the code may compute derivatives wrt constants.
import NaNMath:
sin,
cos,
tan,
asin,
acos,
acosh,
atanh,
log,
log2,
log10,
lgamma,
log1p,
pow,
sqrt
include("Coloring/Coloring.jl")
include("graph_tools.jl")
include("sizes.jl")
include("types.jl")
include("utils.jl")
include("reverse_mode.jl")
include("forward_over_reverse.jl")
include("mathoptinterface_api.jl")
include("MOI_Nonlinear_fork.jl")
end # module