CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
lang_latex_custom_var_name_gen.hpp
1#ifndef CPPAD_CG_LANG_LATEX_CUSTOM_VAR_NAME_GEN_INCLUDED
2#define CPPAD_CG_LANG_LATEX_CUSTOM_VAR_NAME_GEN_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2014 Ciengis
6 * Copyright (C) 2018 Joao Leal
7 *
8 * CppADCodeGen is distributed under multiple licenses:
9 *
10 * - Eclipse Public License Version 1.0 (EPL1), and
11 * - GNU General Public License Version 3 (GPL3).
12 *
13 * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14 * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15 * ----------------------------------------------------------------------------
16 * Author: Joao Leal
17 */
18
19namespace CppAD {
20namespace cg {
21
28template<class Base>
30protected:
32 // the custom names for the dependent variables
33 const std::vector<std::string> depNames_;
34 // the custom names for the independent variables
35 const std::vector<std::string> indepNames_;
36public:
37
38 LangLatexCustomVariableNameGenerator(const std::vector<std::string>& depNames,
39 const std::vector<std::string>& indepNames,
40 const std::string& depName = "y",
41 const std::string& indepName = "x",
42 const std::string& tmpName = "v",
43 const std::string& tmpArrayName = "\\mathbf{a}",
44 const std::string& tmpSparseArrayName = "\\mathbf{s}") :
45 LangLatexDefaultVariableNameGenerator<Base>(depName, indepName, tmpName, tmpArrayName, tmpSparseArrayName),
46 depNames_(depNames),
47 indepNames_(indepNames) {
48 }
49
50 inline virtual ~LangLatexCustomVariableNameGenerator() = default;
51
52 std::string generateDependent(size_t index) override {
53 if (index < depNames_.size() && !depNames_[index].empty()) {
54 return depNames_[index];
55 } else {
56 return Super::generateDependent(index);
57 }
58 }
59
60 std::string generateIndependent(const OperationNode<Base>& independent,
61 size_t id) override {
62 size_t index = id - 1;
63 if (index < indepNames_.size() && !indepNames_[index].empty()) {
64 return indepNames_[index];
65 } else {
66 return Super::generateIndependent(independent, id);
67 }
68 }
69
71 size_t idFirst,
72 const OperationNode<Base>& indepSecond,
73 size_t idSecond) override {
74 size_t index1 = idFirst - 1;
75 size_t index2 = idSecond - 1;
76
77 if ((index1 > indepNames_.size() || indepNames_[index1].empty()) &&
78 (index2 > indepNames_.size() || indepNames_[index2].empty())) {
79 return index1 + 1 == index2;
80 } else {
81 return false; // individual names used (not elements of arrays)
82 }
83 }
84
86 size_t id1,
87 const OperationNode<Base>& indep2,
88 size_t id2) override {
89 size_t index1 = id1 - 1;
90 size_t index2 = id2 - 1;
91
92 return (index1 > indepNames_.size() || indepNames_[index1].empty()) &&
93 (index2 > indepNames_.size() || indepNames_[index2].empty());
94 }
95
96};
97
98} // END cg namespace
99} // END CppAD namespace
100
101#endif
std::string generateIndependent(const OperationNode< Base > &independent, size_t id) override
bool isConsecutiveInIndepArray(const OperationNode< Base > &indepFirst, size_t idFirst, const OperationNode< Base > &indepSecond, size_t idSecond) override
bool isInSameIndependentArray(const OperationNode< Base > &indep1, size_t id1, const OperationNode< Base > &indep2, size_t id2) override
std::string generateIndependent(const OperationNode< Base > &independent, size_t id) override