|
| 1 | +# Copyright (c) 2017: Miles Lubin and contributors |
| 2 | +# Copyright (c) 2017: Google Inc. |
| 3 | +# |
| 4 | +# Use of this source code is governed by an MIT-style license that can be found |
| 5 | +# in the LICENSE.md file or at https://opensource.org/licenses/MIT. |
| 6 | + |
1 | 7 | module ArrayAD |
2 | 8 |
|
3 | | -greet() = print("Hello World!") |
| 9 | +import ForwardDiff |
| 10 | +import MathOptInterface as MOI |
| 11 | +const Nonlinear = MOI.Nonlinear |
| 12 | +import SparseArrays |
| 13 | + |
| 14 | +""" |
| 15 | + Mode() <: AbstractAutomaticDifferentiation |
| 16 | +
|
| 17 | +Fork of `MOI.Nonlinear.SparseReverseMode` to add array support. |
| 18 | +""" |
| 19 | +struct Mode <: MOI.Nonlinear.AbstractAutomaticDifferentiation end |
| 20 | + |
| 21 | +function MOI.Nonlinear.Evaluator( |
| 22 | + model::MOI.Nonlinear.Model, |
| 23 | + ::Mode, |
| 24 | + ordered_variables::Vector{MOI.VariableIndex}, |
| 25 | +) |
| 26 | + return MOI.Nonlinear.Evaluator( |
| 27 | + model, |
| 28 | + NLPEvaluator(model, ordered_variables), |
| 29 | + ) |
| 30 | +end |
| 31 | + |
| 32 | +# Override basic math functions to return NaN instead of throwing errors. |
| 33 | +# This is what NLP solvers expect, and sometimes the results aren't needed |
| 34 | +# anyway, because the code may compute derivatives wrt constants. |
| 35 | +import NaNMath: |
| 36 | + sin, |
| 37 | + cos, |
| 38 | + tan, |
| 39 | + asin, |
| 40 | + acos, |
| 41 | + acosh, |
| 42 | + atanh, |
| 43 | + log, |
| 44 | + log2, |
| 45 | + log10, |
| 46 | + lgamma, |
| 47 | + log1p, |
| 48 | + pow, |
| 49 | + sqrt |
| 50 | + |
| 51 | +include("Coloring/Coloring.jl") |
| 52 | +include("graph_tools.jl") |
| 53 | +include("types.jl") |
| 54 | +include("utils.jl") |
| 55 | + |
| 56 | +include("reverse_mode.jl") |
| 57 | +include("forward_over_reverse.jl") |
| 58 | +include("mathoptinterface_api.jl") |
4 | 59 |
|
5 | | -end # module ArrayAD |
| 60 | +end # module |
0 commit comments