Skip to content

Commit 640fffb

Browse files
authored
Merge pull request #51 from joaoleal/develop
Develop
2 parents 09d7c8d + 56b94d9 commit 640fffb

19 files changed

+479
-81
lines changed

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
1919

2020
PROJECT(cppadcg CXX C)
2121

22-
SET(cppadcg_version "2.4.1" )
22+
SET(cppadcg_version "2.4.2" )
2323
SET(cppadcg_url "https://github.com/joaoleal/CppADCodeGen" )
2424
SET(cppadcg_description "A C++ Algorithmic Differentiation Package with Source Code Generation" )
2525

Diff for: debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
cppadcodegen (2.4.2-1) unstable; urgency=low
2+
3+
* fix missing inline
4+
5+
-- Joao Leal <[email protected]> Thu, 12 Mar 2020 18:00:00 +0000
6+
17
cppadcodegen (2.4.1-1) unstable; urgency=low
28

39
* fix cppad version in pkgconfig

Diff for: include/cppad/cg/lang/c/language_c.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ class LanguageC : public Language<Base> {
678678
_currentLoops.clear();
679679
_atomicFuncArrays.clear();
680680
_streamStack.clear();
681+
_dependentIDs.clear();
681682

682683
// save some info
683684
_info = std::move(info);

Diff for: include/cppad/cg/lang/dot/language_dot.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ class LanguageDot : public Language<Base> {
241241
_code.str("");
242242
_ss.str("");
243243
_currentLoops.clear();
244+
_dependentIDs.clear();
244245
parIdx_ = 0;
245246

246247
// save some info
@@ -520,7 +521,7 @@ class LanguageDot : public Language<Base> {
520521
op == CGOpCode::IndexDeclaration;
521522
}
522523

523-
virtual bool requiresVariableArgument(enum CGOpCode op, size_t argIndex) const override {
524+
bool requiresVariableArgument(enum CGOpCode op, size_t argIndex) const override {
524525
return op == CGOpCode::CondResult;
525526
}
526527

@@ -579,7 +580,7 @@ class LanguageDot : public Language<Base> {
579580
return *var.getName();
580581
}
581582

582-
virtual bool requiresVariableDependencies() const override {
583+
bool requiresVariableDependencies() const override {
583584
return false;
584585
}
585586

@@ -1469,10 +1470,10 @@ class LanguageDot : public Language<Base> {
14691470
};
14701471

14711472
template<class Base>
1472-
const std::string LanguageDot<Base>::_C_STATIC_INDEX_ARRAY = "index";
1473+
const std::string LanguageDot<Base>::_C_STATIC_INDEX_ARRAY = "index"; // NOLINT(cert-err58-cpp)
14731474

14741475
template<class Base>
1475-
const std::string LanguageDot<Base>::_C_SPARSE_INDEX_ARRAY = "idx";
1476+
const std::string LanguageDot<Base>::_C_SPARSE_INDEX_ARRAY = "idx"; // NOLINT(cert-err58-cpp)
14761477

14771478
} // END cg namespace
14781479
} // END CppAD namespace

Diff for: include/cppad/cg/lang/latex/language_latex.hpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ class LanguageLatex : public Language<Base> {
693693
_inEquationEnv = false;
694694
auxArrayName_ = "";
695695
_currentLoops.clear();
696+
_dependentIDs.clear();
696697

697698

698699
// save some info
@@ -746,7 +747,7 @@ class LanguageLatex : public Language<Base> {
746747
const std::vector<FuncArgument>& indArg = _nameGen->getIndependent();
747748
const std::vector<FuncArgument>& depArg = _nameGen->getDependent();
748749
const std::vector<FuncArgument>& tmpArg = _nameGen->getTemporary();
749-
CPPADCG_ASSERT_KNOWN(!indArg.empty() && depArg.size() > 0,
750+
CPPADCG_ASSERT_KNOWN(!indArg.empty() && !depArg.empty(),
750751
"There must be at least one dependent and one independent argument")
751752
CPPADCG_ASSERT_KNOWN(tmpArg.size() == 3,
752753
"There must be three temporary variables")
@@ -808,7 +809,6 @@ class LanguageLatex : public Language<Base> {
808809
*/
809810
if (info->zeroDependents) {
810811
// zero initial values
811-
const std::vector<FuncArgument>& depArg = _nameGen->getDependent();
812812
if (!depArg.empty())
813813
checkEquationEnvStart();
814814
for (size_t i = 0; i < depArg.size(); i++) {
@@ -845,7 +845,7 @@ class LanguageLatex : public Language<Base> {
845845
assignCount += printAssignment(node);
846846
}
847847

848-
if (inputLatexFiles.size() > 0 && assignCount > 0) {
848+
if (!inputLatexFiles.empty() && assignCount > 0) {
849849
assignCount = 0;
850850
saveLocalFunction(inputLatexFiles, false);
851851
}
@@ -858,8 +858,8 @@ class LanguageLatex : public Language<Base> {
858858
CPPADCG_ASSERT_KNOWN(tmpArg[0].array,
859859
"The temporary variables must be saved in an array in order to generate multiple functions")
860860
printAlgorithmFileStart(_code);
861-
for (size_t i = 0; i < inputLatexFiles.size(); i++) {
862-
_code << "\\input{" << inputLatexFiles[i] << "}" << _endline;
861+
for (auto & inputLatexFile : inputLatexFiles) {
862+
_code << "\\input{" << inputLatexFile << "}" << _endline;
863863
}
864864
printAlgorithmFileEnd(_code);
865865
}
@@ -1132,14 +1132,14 @@ class LanguageLatex : public Language<Base> {
11321132

11331133
inline const std::string& createVariableName(Node& var) {
11341134
CGOpCode op = var.getOperationType();
1135-
CPPADCG_ASSERT_UNKNOWN(getVariableID(var) > 0);
1136-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::AtomicForward);
1137-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::AtomicReverse);
1138-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::LoopStart);
1139-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::LoopEnd);
1140-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::Index);
1141-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::IndexAssign);
1142-
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::IndexDeclaration);
1135+
CPPADCG_ASSERT_UNKNOWN(getVariableID(var) > 0)
1136+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::AtomicForward)
1137+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::AtomicReverse)
1138+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::LoopStart)
1139+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::LoopEnd)
1140+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::Index)
1141+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::IndexAssign)
1142+
CPPADCG_ASSERT_UNKNOWN(op != CGOpCode::IndexDeclaration)
11431143

11441144
if (var.getName() == nullptr) {
11451145
if (op == CGOpCode::ArrayCreation) {
@@ -1164,8 +1164,8 @@ class LanguageLatex : public Language<Base> {
11641164

11651165
} else if (getVariableID(var) < _minTemporaryVarID) {
11661166
// dependent variable
1167-
std::map<size_t, size_t>::const_iterator it = _dependentIDs.find(getVariableID(var));
1168-
CPPADCG_ASSERT_UNKNOWN(it != _dependentIDs.end());
1167+
auto it = _dependentIDs.find(getVariableID(var));
1168+
CPPADCG_ASSERT_UNKNOWN(it != _dependentIDs.end())
11691169

11701170
size_t index = it->second;
11711171
var.setName(_nameGen->generateDependent(index));
@@ -1948,9 +1948,9 @@ class LanguageLatex : public Language<Base> {
19481948
* the first argument is the condition, following arguments are
19491949
* just extra dependencies that must be defined outside the if
19501950
*/
1951-
CPPADCG_ASSERT_KNOWN(node.getOperationType() == CGOpCode::StartIf, "Invalid node type");
1952-
CPPADCG_ASSERT_KNOWN(node.getArguments().size() >= 1, "Invalid number of arguments for an 'if start' operation");
1953-
CPPADCG_ASSERT_KNOWN(node.getArguments()[0].getOperation() != nullptr, "Invalid argument for an 'if start' operation");
1951+
CPPADCG_ASSERT_KNOWN(node.getOperationType() == CGOpCode::StartIf, "Invalid node type")
1952+
CPPADCG_ASSERT_KNOWN(node.getArguments().size() >= 1, "Invalid number of arguments for an 'if start' operation")
1953+
CPPADCG_ASSERT_KNOWN(node.getArguments()[0].getOperation() != nullptr, "Invalid argument for an 'if start' operation")
19541954

19551955
checkEquationEnvEnd();
19561956

@@ -2053,7 +2053,7 @@ class LanguageLatex : public Language<Base> {
20532053
}
20542054

20552055
virtual void printUserCustom(Node& node) {
2056-
CPPADCG_ASSERT_KNOWN(node.getOperationType() == CGOpCode::UserCustom, "Invalid node type");
2056+
CPPADCG_ASSERT_KNOWN(node.getOperationType() == CGOpCode::UserCustom, "Invalid node type")
20572057

20582058
throw CGException("Unable to generate Latex for user custom operation nodes.");
20592059
}
@@ -2171,35 +2171,35 @@ class LanguageLatex : public Language<Base> {
21712171
};
21722172

21732173
template<class Base>
2174-
const std::string LanguageLatex<Base>::_COMP_OP_LT = "<";
2174+
const std::string LanguageLatex<Base>::_COMP_OP_LT = "<"; // NOLINT(cert-err58-cpp)
21752175
template<class Base>
2176-
const std::string LanguageLatex<Base>::_COMP_OP_LE = "\\le";
2176+
const std::string LanguageLatex<Base>::_COMP_OP_LE = "\\le"; // NOLINT(cert-err58-cpp)
21772177
template<class Base>
2178-
const std::string LanguageLatex<Base>::_COMP_OP_EQ = "==";
2178+
const std::string LanguageLatex<Base>::_COMP_OP_EQ = "=="; // NOLINT(cert-err58-cpp)
21792179
template<class Base>
2180-
const std::string LanguageLatex<Base>::_COMP_OP_GE = "\\ge";
2180+
const std::string LanguageLatex<Base>::_COMP_OP_GE = "\\ge"; // NOLINT(cert-err58-cpp)
21812181
template<class Base>
2182-
const std::string LanguageLatex<Base>::_COMP_OP_GT = ">";
2182+
const std::string LanguageLatex<Base>::_COMP_OP_GT = ">"; // NOLINT(cert-err58-cpp)
21832183
template<class Base>
2184-
const std::string LanguageLatex<Base>::_COMP_OP_NE = "\\ne";
2184+
const std::string LanguageLatex<Base>::_COMP_OP_NE = "\\ne"; // NOLINT(cert-err58-cpp)
21852185

21862186
template<class Base>
2187-
const std::string LanguageLatex<Base>::_C_STATIC_INDEX_ARRAY = "index";
2187+
const std::string LanguageLatex<Base>::_C_STATIC_INDEX_ARRAY = "index"; // NOLINT(cert-err58-cpp)
21882188

21892189
template<class Base>
2190-
const std::string LanguageLatex<Base>::_C_SPARSE_INDEX_ARRAY = "idx";
2190+
const std::string LanguageLatex<Base>::_C_SPARSE_INDEX_ARRAY = "idx"; // NOLINT(cert-err58-cpp)
21912191

21922192
template<class Base>
2193-
const std::string LanguageLatex<Base>::_ATOMIC_TX = "atx";
2193+
const std::string LanguageLatex<Base>::_ATOMIC_TX = "atx"; // NOLINT(cert-err58-cpp)
21942194

21952195
template<class Base>
2196-
const std::string LanguageLatex<Base>::_ATOMIC_TY = "aty";
2196+
const std::string LanguageLatex<Base>::_ATOMIC_TY = "aty"; // NOLINT(cert-err58-cpp)
21972197

21982198
template<class Base>
2199-
const std::string LanguageLatex<Base>::_ATOMIC_PX = "apx";
2199+
const std::string LanguageLatex<Base>::_ATOMIC_PX = "apx"; // NOLINT(cert-err58-cpp)
22002200

22012201
template<class Base>
2202-
const std::string LanguageLatex<Base>::_ATOMIC_PY = "apy";
2202+
const std::string LanguageLatex<Base>::_ATOMIC_PY = "apy"; // NOLINT(cert-err58-cpp)
22032203

22042204
} // END cg namespace
22052205
} // END CppAD namespace

Diff for: include/cppad/cg/lang/mathml/language_mathml.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ class LanguageMathML : public Language<Base> {
545545
_currentLoops.clear();
546546
depConstIds_.clear();
547547
depIsIndepIds_.clear();
548+
_dependentIDs.clear();
548549

549550

550551
// save some info
@@ -2163,22 +2164,22 @@ class LanguageMathML : public Language<Base> {
21632164
};
21642165

21652166
template<class Base>
2166-
const std::string LanguageMathML<Base>::_C_STATIC_INDEX_ARRAY = "index";
2167+
const std::string LanguageMathML<Base>::_C_STATIC_INDEX_ARRAY = "index"; // NOLINT(cert-err58-cpp)
21672168

21682169
template<class Base>
2169-
const std::string LanguageMathML<Base>::_C_SPARSE_INDEX_ARRAY = "idx";
2170+
const std::string LanguageMathML<Base>::_C_SPARSE_INDEX_ARRAY = "idx"; // NOLINT(cert-err58-cpp)
21702171

21712172
template<class Base>
2172-
const std::string LanguageMathML<Base>::_ATOMIC_TX = "atx";
2173+
const std::string LanguageMathML<Base>::_ATOMIC_TX = "atx"; // NOLINT(cert-err58-cpp)
21732174

21742175
template<class Base>
2175-
const std::string LanguageMathML<Base>::_ATOMIC_TY = "aty";
2176+
const std::string LanguageMathML<Base>::_ATOMIC_TY = "aty"; // NOLINT(cert-err58-cpp)
21762177

21772178
template<class Base>
2178-
const std::string LanguageMathML<Base>::_ATOMIC_PX = "apx";
2179+
const std::string LanguageMathML<Base>::_ATOMIC_PX = "apx"; // NOLINT(cert-err58-cpp)
21792180

21802181
template<class Base>
2181-
const std::string LanguageMathML<Base>::_ATOMIC_PY = "apy";
2182+
const std::string LanguageMathML<Base>::_ATOMIC_PY = "apy"; // NOLINT(cert-err58-cpp)
21822183

21832184
} // END cg namespace
21842185
} // END CppAD namespace

Diff for: include/cppad/cg/util.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ inline std::string implode(const std::vector<std::string>& text,
805805
}
806806
}
807807

808-
std::string readStringFromFile(const std::string& path) {
808+
inline std::string readStringFromFile(const std::string& path) {
809809
std::ifstream iStream;
810810
iStream.open(path);
811811

Diff for: test/cppad/cg/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_cppadcg_test(array_view.cpp)
2121
add_cppadcg_test(inputstream.cpp)
2222
add_cppadcg_test(temporary.cpp)
2323
add_cppadcg_test(mult_sparsity_pattern.cpp)
24+
add_cppadcg_test(multi_object_1.cpp multi_object.cpp)
2425

2526
ADD_SUBDIRECTORY(extra)
2627
ADD_SUBDIRECTORY(operations)

Diff for: test/cppad/cg/model/lang/c/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# --------------------------------------------------------------------------
22
# CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
3-
# Copyright (C) 2019 Ciengis
3+
# Copyright (C) 2013 Ciengis
4+
# Copyright (C) 2019 Joao Leal
45
#
56
# CppADCodeGen is distributed under multiple licenses:
67
#
@@ -20,3 +21,4 @@ SET(CMAKE_BUILD_TYPE DEBUG)
2021
# tests
2122
################################################################################
2223
add_cppadcg_test(lang_c.cpp)
24+
add_cppadcg_test(lang_c_reset.cpp)
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* --------------------------------------------------------------------------
22
* CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
33
* Copyright (C) 2012 Ciengis
4+
* Copyright (C) 2020 Joao Leal
45
*
56
* CppADCodeGen is distributed under multiple licenses:
67
*
@@ -13,63 +14,49 @@
1314
* Author: Joao Leal
1415
*/
1516

16-
#include <cppad/cg/cppadcg.hpp>
17+
#include "CppADCGTest.hpp"
1718

18-
#include "gcc_load_dynamic.hpp"
19+
using namespace CppAD;
20+
using namespace CppAD::cg;
1921

20-
namespace {
21-
22-
bool HandlerReset1() {
22+
TEST_F(CppADCGTest, HandlerReset) {
2323
using namespace CppAD;
2424
using namespace std;
2525

2626
CodeHandler<double> handler(20);
2727

2828
// independent variables of CppAD
29-
vector<CG<double> > u(3);
30-
handler.makeVariables(u);
29+
std::vector<CG<double> > x(3);
30+
handler.makeVariables(x);
3131

3232
// independent variables of CppAD
33-
vector<AD<CG<double> > > U(3);
34-
U[0] = u[0];
35-
U[1] = u[1];
36-
U[2] = u[2];
33+
std::vector<AD<CG<double> > > ax(3);
34+
ax[0] = x[0];
35+
ax[1] = x[1];
36+
ax[2] = x[2];
3737

38-
CppAD::Independent(U);
38+
CppAD::Independent(ax);
3939

4040
// dependent variable of CppAD
41-
vector<AD<CG<double> > > w(3);
42-
w[0] = u[0] + 2.0;
43-
w[1] = u[1] + 3.0;
44-
w[2] = u[2] * 4.0;
41+
std::vector<AD<CG<double> > > ay(3);
42+
ay[0] = x[0] + 2.0;
43+
ay[1] = x[1] + 3.0;
44+
ay[2] = x[2] * 4.0;
45+
46+
CppAD::ADFun<CG<double> > f(ax, ay);
4547

46-
CppAD::ADFun<CG<double> > f(U, w);
48+
std::vector<CG<double> > dep = f.Forward(0, x);
4749

48-
vector<CG<double> > dep = f.Forward(0, u);
50+
LanguageC<double> languageC("double");
51+
LangCDefaultVariableNameGenerator<double> nameGen;
4952

5053
ostringstream code;
51-
handler.generateCode(code, dep);
54+
handler.generateCode(code, languageC, dep, nameGen);
5255
string code1 = code.str();
5356

5457
code.str("");
55-
handler.generateCode(code, dep);
58+
handler.generateCode(code, languageC, dep, nameGen);
5659
string code2 = code.str();
5760

58-
if (code1 == code2) {
59-
return true;
60-
} else {
61-
cerr << "\n ############################\n\n" << code1
62-
<< "\n ############################\n\n" << code2
63-
<< "\n ############################\n\n";
64-
return false;
65-
}
66-
67-
}
68-
69-
}
70-
71-
bool HandlerReset() {
72-
bool ok = true;
73-
ok &= HandlerReset1();
74-
return ok;
61+
ASSERT_EQ(code1, code2);
7562
}

Diff for: test/cppad/cg/model/lang/dot/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# --------------------------------------------------------------------------
22
# CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
33
# Copyright (C) 2016 Ciengis
4+
# Copyright (C) 2020 Joao Leal
45
#
56
# CppADCodeGen is distributed under multiple licenses:
67
#
@@ -32,3 +33,4 @@ ENDFUNCTION()
3233
# tests
3334
################################################################################
3435
add_cppadcg_dot_test(dot.cpp)
36+
add_cppadcg_dot_test(lang_dot_reset.cpp)

0 commit comments

Comments
 (0)