Skip to content

Commit

Permalink
Fixed minor compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoleal committed Jun 16, 2024
1 parent 062f00b commit 447503b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 123 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
- run:
name: Execute Tests
command: |
cd build
CTEST_OUTPUT_ON_FAILURE=TRUE make test
- run:
name: Test Installation
Expand Down
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Author: Joao Leal
#
# ----------------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.0...3.27.4)

PROJECT(cppadcg CXX C)

Expand Down Expand Up @@ -120,11 +120,9 @@ SET(install_python_location "${CMAKE_INSTALL_PREFIX}/share/cppadcg/
# ----------------------------------------------------------------------------
# Define some optional compiler flags
# ----------------------------------------------------------------------------
IF(CMAKE_VERSION VERSION_GREATER "3.1.0")
# aim for this version which has explicit support for c++11
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED TRUE)
ENDIF()

SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED TRUE)

IF(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(warning_flags "-Wall") # enable as many warnings as possible
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ See epl-v10.txt and gpl3.txt for a copy of the licenses.

CppADCodeGen is a C++14 header only library, therefore there aren't many dependencies:

- **CppAD** (2020),
- [**CppAD**](https://github.com/coin-or/CppAD) (2024),
- A **C++14** compiler (such as GCC and Clang),
- Clang/LLVM (only required for JIT compilation; supported versions <= v9.0), and
- Eigen 3 (required when DAE differentiation index reduction is used).
- [Eigen 3](https://gitlab.com/libeigen/eigen) (required when DAE differentiation index reduction is used).

Runtime compilation and dynamic linking:
- Linux (it might be very easy to support other OSes but it is not implemented yet)
Expand All @@ -49,32 +49,32 @@ Runtime compilation and dynamic linking:
### General installation ###

Get the sources from GitHub:
```
```sh
git clone https://github.com/joaoleal/CppADCodeGen.git CppADCodeGen
```
Create a new folder to build the project:
```
```sh
mkdir cppadcg-build
```
Build the project (no compilation of C/C++ occurs, just generation of header files):
```
```sh
cd cppadcg-build
cmake ../CppADCodeGen
```
Either install the project in your system:
```
```sh
make install
```
or to some other folder:
```
```sh
make DESTDIR=someotherfolder install
```

### Debian/Ubuntu ###

A debian installation package can be created at the root of the project.
Typically you can create the installer by just typing:
```
```sh
dpkg-buildpackage
```
It will create a debian package outside the project's folder.
Expand All @@ -88,34 +88,34 @@ The folder example includes some simple use cases.
## Testing ##

Get the sources from GitHub:
```
```sh
git clone https://github.com/joaoleal/CppADCodeGen.git CppADCodeGen
```
Create a new folder for the tests:
```
```sh
cd make-build-debug
cmake ../CppADCodeGen
```
Testing requires [google-test](https://github.com/google/googletest) (version 1.8.1).
Either install it in your system or configure CppADCodeGen to download the sources from GitHub by replacing the previous line with:
```
```sh
cmake -DGOOGLETEST_GIT=ON ../CppADCodeGen
```

Then compile the tests:
```
```sh
make build_tests
```

Run the complete set of tests:
```
```sh
make test
```
If [valgrind](https://valgrind.org/) is available in your system, CppADCodeGen will also perform memory checks which can
lead to a very lengthy test execution.
It is possible to disable memory validations by turning off the CMake option `USE_VALGRIND`.
For instance, by calling the following command before running the tests:
```
```sh
cmake -DUSE_VALGRIND=OFF ../CppADCodeGen
```
---
Expand Down
2 changes: 1 addition & 1 deletion include/cppad/cg/lang/c/language_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class LanguageC : public Language<Base> {
_ss << _spaces << _baseTypeName << " " << tmpArg[0].name << "[" << size << "];\n";
}
} else if (_temporary.size() > 0) {
for (const std::pair<size_t, Node*>& p : _temporary) {
for (const auto& p : _temporary) {
Node* var = p.second;
if (var->getName() == nullptr) {
var->setName(_nameGen->generateTemporary(*var, getVariableID(*var)));
Expand Down
2 changes: 1 addition & 1 deletion include/cppad/cg/lang/dot/language_dot_index_patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ inline void LanguageDot<Base>::printRandomIndexPatternDeclaration(std::ostringst
const std::map<size_t, size_t>& x2y = ip1->getValues();

std::vector<size_t> y(x2y.rbegin()->first + 1);
for (const std::pair<size_t, size_t>& p : x2y)
for (const auto& p : x2y)
y[p.first] = p.second;

printStaticIndexArray(os, ip->getName(), y);
Expand Down
20 changes: 10 additions & 10 deletions include/cppad/cg/model/patterns/model_c_source_gen_loops_for1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ModelCSourceGen<Base>::prepareSparseForwardOneWithLoops(const std::map<size
std::vector<size_t> locations(nnz);

size_t p = 0;
for (const pair<size_t, std::vector<size_t> >& itJ : elements) {//loop variables
for (const auto& itJ : elements) {//loop variables
size_t j = itJ.first;
const std::vector<size_t>& r = itJ.second;

Expand Down Expand Up @@ -130,15 +130,15 @@ void ModelCSourceGen<Base>::prepareSparseForwardOneWithLoops(const std::map<size
x, hasAtomics);

map<size_t, std::vector<CGBase> > jacNl; // by column
for (const pair<size_t, map<size_t, CGBase> >& itDydxT : dydxT) {
for (const auto& itDydxT : dydxT) {
size_t j = itDydxT.first;
const map<size_t, CGBase>& dydxjT = itDydxT.second;

// prepare space for the Jacobian of the original equations
std::vector<CGBase>& col = jacNl[j];
col.resize(elements.at(j).size());

for (const pair<size_t, CGBase>& itiv : dydxjT) {
for (const auto& itiv : dydxjT) {
size_t inl = itiv.first;

if (inl < nonIndexdedEqSize) {
Expand Down Expand Up @@ -224,7 +224,7 @@ void ModelCSourceGen<Base>::prepareSparseForwardOneWithLoops(const std::map<size

map<size_t, set<size_t> > localIterCount2Jcols;

for (const pair<size_t, set<size_t> >& itJcol2It : group.jCol2Iterations) {
for (const auto& itJcol2It : group.jCol2Iterations) {
size_t jcol = itJcol2It.first;
size_t itCount = itJcol2It.second.size();
localIterCount2Jcols[itCount].insert(jcol);
Expand All @@ -241,7 +241,7 @@ void ModelCSourceGen<Base>::prepareSparseForwardOneWithLoops(const std::map<size
*/
map<size_t, map<size_t, size_t> > jcol2localIt2ModelIt;

for (const pair<size_t, set<size_t> >& itJcol2It : group.jCol2Iterations) {
for (const auto& itJcol2It : group.jCol2Iterations) {
size_t jcol = itJcol2It.first;

map<size_t, size_t>& localIt2ModelIt = jcol2localIt2ModelIt[jcol];
Expand Down Expand Up @@ -274,7 +274,7 @@ void ModelCSourceGen<Base>::prepareSparseForwardOneWithLoops(const std::map<size
if (createsLoop) {
map<size_t, size_t> jcol2litCount;

for (const pair<size_t, set<size_t> >& itJcol2Its : group.jCol2Iterations) {
for (const auto& itJcol2Its : group.jCol2Iterations) {
size_t jcol = itJcol2Its.first;
jcol2litCount[jcol] = itJcol2Its.second.size();
}
Expand Down Expand Up @@ -589,7 +589,7 @@ std::map<JacobianTermContrib<Base>, std::set<size_t> > groupForOneByContrib(cons
const JacobianWithLoopsRowInfo& row = loopEqInfo[i];

// indexed
for (const pair<size_t, std::vector<size_t> >& it : row.indexedPositions) {
for (const auto& it : row.indexedPositions) {
size_t tapeJ = it.first;
const std::vector<size_t>& positions = it.second;
map<size_t, set<size_t> >& jcol2Iter = indexed2jcol2Iter[tapeJ];
Expand All @@ -606,7 +606,7 @@ std::map<JacobianTermContrib<Base>, std::set<size_t> > groupForOneByContrib(cons
}

// non-indexed
for (const pair<size_t, std::vector<size_t> >& it : row.nonIndexedPositions) {
for (const auto& it : row.nonIndexedPositions) {
size_t j = it.first;
const std::vector<size_t>& positions = it.second;
set<size_t>& jcol2Iter = nonIndexed2Iter[j];
Expand Down Expand Up @@ -680,7 +680,7 @@ inline void subgroupForOneByContrib(const std::vector<JacobianWithLoopsRowInfo>&
/**
*
*/
for (const pair<Forward1Jcol2Iter, JacobianTermContrib<Base> >& itK2C : contribs) {
for (const auto& itK2C : contribs) {
const Forward1Jcol2Iter& jcol2Iters = itK2C.first;
const JacobianTermContrib<Base>& hc = itK2C.second;

Expand Down Expand Up @@ -825,7 +825,7 @@ std::pair<CG<Base>, IndexPattern*> createForwardOneElement(CodeHandler<Base>& ha
*/
map<size_t, size_t> locationsIter2Pos;

for (const std::pair<size_t, size_t>& itIt : iter2jcols) {
for (const auto& itIt : iter2jcols) {
size_t iter = itIt.first;
size_t jcol = itIt.second;
CPPADCG_ASSERT_UNKNOWN(positions[iter] != (std::numeric_limits<size_t>::max)());
Expand Down
2 changes: 1 addition & 1 deletion include/cppad/cg/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ inline void print(const Base& v) {

template<class Key, class Value>
inline void print(const std::map<Key, Value>& m) {
for (const std::pair<Key, Value>& p : m) {
for (const auto& p : m) {
std::cout << p.first << " : ";
print(p.second);
std::cout << std::endl;
Expand Down
106 changes: 16 additions & 90 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,108 +22,35 @@ SET(CMAKE_BUILD_TYPE DEBUG)
################################################################################
INCLUDE(ExternalProject)

# Set default ExternalProject root directory
SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/test/googletest)

# Add gtest
OPTION(GOOGLETEST_GIT "Download GoogleTest from the GIT repositoty" OFF)
IF(GOOGLETEST_GIT)
# Download from SVN repository
ExternalProject_Add(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
TIMEOUT 10
# Force separate output paths for debug and release builds to allow easy
# identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
-Dgtest_force_shared_crt=ON
# Disable install step
INSTALL_COMMAND ""
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
ELSE()
# find installed in system
FIND_PATH(GOOGLETEST_SOURCE_DIR NAMES "src/gtest_main.cc"
HINTS $ENV{GOOGLETEST_HOME}
"/usr/src/gtest/" )
IF(NOT IS_DIRECTORY ${GOOGLETEST_SOURCE_DIR})
MESSAGE(FATAL_ERROR "GoogleTest source folder not found")
ENDIF()

ExternalProject_Add(
googletest
URL ${GOOGLETEST_SOURCE_DIR}
# Force separate output paths for debug and release builds to allow easy
# identification of correct lib in subsequent TARGET_LINK_LIBRARIES commands
CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs
-Dgtest_force_shared_crt=ON
# Disable install step
INSTALL_COMMAND ""
# Wrap download, configure and build steps in a script to log output
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON)
ENDIF()

# Specify include dir
ExternalProject_Get_Property(googletest source_dir)
SET(gtest_source_dir ${source_dir})

# Specify MainTest's link libraries
ExternalProject_Get_Property(googletest binary_dir)
IF(GOOGLETEST_GIT)
SET(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest)
ELSE()
SET(GTEST_LIBS_DIR ${binary_dir})
ENDIF()
# Download from GitHub
INCLUDE(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip)

INCLUDE_DIRECTORIES("${gtest_source_dir}/googletest/include")
# For Windows: Prevent overriding the parent project's compiler/linker settings
SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

SET(GTEST_LIBRARY_PATH ${GTEST_LIBS_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a)
SET(GTEST_MAIN_PATH ${GTEST_LIBS_DIR}/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a)

ADD_LIBRARY(gtest UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(gtest PROPERTIES
"IMPORTED_LOCATION" "${GTEST_LIBRARY_PATH}"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
"INTERFACE_INCLUDE_DIRECTORIES" "${GTEST_INCLUDE_DIRS}")
ADD_DEPENDENCIES(gtest googletest)

ADD_LIBRARY(gtestmain UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(gtestmain PROPERTIES
"IMPORTED_LOCATION" "${GTEST_MAIN_PATH}"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
"INTERFACE_INCLUDE_DIRECTORIES" "${GTEST_INCLUDE_DIRS}")
ADD_DEPENDENCIES(gtestmain googletest)
INCLUDE(GoogleTest)

################################################################################
# add gtest dependency
################################################################################
FUNCTION(add_gest_link_libraries test_target_name use_main)
FUNCTION(add_gest_link_libraries test_target_name)
IF(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
TARGET_LINK_LIBRARIES(${test_target_name} gtest)
IF(${use_main})
TARGET_LINK_LIBRARIES(${test_target_name} gtestmain)
ENDIF()

TARGET_LINK_LIBRARIES(${test_target_name} GTest::gtest_main)

TARGET_LINK_LIBRARIES(${test_target_name} pthread)
ELSE()
TARGET_LINK_LIBRARIES(${test_target_name}
debug ${GTEST_LIBS_DIR}/DebugLibs/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${GTEST_LIBS_DIR}/ReleaseLibs/${CMAKE_FIND_LIBRARY_PREFIXES}gtest${CMAKE_FIND_LIBRARY_SUFFIXES})
IF(${use_main})
TARGET_LINK_LIBRARIES(${test_target_name}
debug ${GTEST_LIBS_DIR}/DebugLibs/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${CMAKE_FIND_LIBRARY_SUFFIXES}
optimized ${GTEST_LIBS_DIR}/ReleaseLibs/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main${CMAKE_FIND_LIBRARY_SUFFIXES})
ENDIF()
TARGET_LINK_LIBRARIES(${test_target_name} GTest::gtest_main)

ENDIF()

# Create dependency of test on googletest
ADD_DEPENDENCIES(${test_target_name} googletest)
#ADD_DEPENDENCIES(${test_target_name} googletest)
ENDFUNCTION()

################################################################################
Expand Down Expand Up @@ -252,7 +179,6 @@ IF(USE_PRECOMPILED_HEADERS)
ENDIF()

ADD_SUBDIRECTORY(cppad/cg)
#ADD_SUBDIRECTORY(zoot)

FILE(COPY "${CMAKE_CURRENT_SOURCE_DIR}/valgrind.sh"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

0 comments on commit 447503b

Please sign in to comment.