Skip to content

Commit

Permalink
cppad: Fix unit tests and example
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisv committed Jan 15, 2024
1 parent 0d1e2eb commit acaec06
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ IF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)
ADD_PINOCCHIO_CPP_EXAMPLE(codegen-crba)
SET_PROPERTY(TARGET example-cpp-codegen-crba PROPERTY CXX_STANDARD 11)
TARGET_LINK_LIBRARIES(example-cpp-codegen-crba PUBLIC ${CMAKE_DL_LIBS} ${cppad_LIBRARY})
TARGET_COMPILE_DEFINITIONS(example-cpp-codegen-crba PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
ENDIF(CPPADCG_FOUND AND BUILD_WITH_CODEGEN_SUPPORT AND BUILD_WITH_URDF_SUPPORT)

2 changes: 1 addition & 1 deletion examples/codegen/codegen-crba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, const char ** argv)

// Generate the lib if it does not exist and load it afterwards.
crba_code_gen.initLib();
crba_code_gen.loadLib();
crba_code_gen.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

// Use it with a random configuration samples in the bounds of the joint limits
VectorXd q = randomConfiguration(model);
Expand Down
10 changes: 8 additions & 2 deletions include/pinocchio/codegen/code-generator-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ namespace pinocchio
CppAD::cg::ModelCSourceGen<Scalar> & codeGenerator()
{ return *cgen_ptr; }

void compileLib()
void compileLib(const std::string& gccPath = "/usr/bin/gcc")
{
CppAD::cg::GccCompiler<Scalar> compiler;
CppAD::cg::GccCompiler<Scalar> compiler(gccPath);
std::vector<std::string> compile_options = compiler.getCompileFlags();
compile_options[0] = "-Ofast";
compiler.setCompileFlags(compile_options);
Expand All @@ -99,6 +99,12 @@ namespace pinocchio
return file.good();
}

void compileAndLoadLib(const std::string& gccPath)
{
compileLib(gccPath);
loadLib(false);
}

void loadLib(const bool generate_if_not_exist = true)
{
if(!existLib() && generate_if_not_exist)
Expand Down
1 change: 1 addition & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ MACRO(ADD_CPPADCG_UNIT_TEST name)
ADD_DEPENDENCIES(test-cppadcg test-cpp-${name})
SET_PROPERTY(TARGET test-cpp-${name} PROPERTY CXX_STANDARD 11)
TARGET_LINK_LIBRARIES(test-cpp-${name} PUBLIC ${cppad_LIBRARY} ${CMAKE_DL_LIBS})
TARGET_COMPILE_DEFINITIONS(test-cpp-${name} PUBLIC PINOCCHIO_CXX_COMPILER=\"${CMAKE_CXX_COMPILER}\")
ENDMACRO()

IF(BUILD_WITH_AUTODIFF_SUPPORT)
Expand Down
2 changes: 1 addition & 1 deletion unittest/cppadcg-algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
// compile source code
CppAD::cg::DynamicModelLibraryProcessor<Scalar> p(libcgen);

CppAD::cg::GccCompiler<Scalar> compiler;
CppAD::cg::GccCompiler<Scalar> compiler(PINOCCHIO_CXX_COMPILER);
std::unique_ptr<CppAD::cg::DynamicLib<Scalar>> dynamicLib = p.createDynamicLibrary(compiler);

// save to files (not really required)
Expand Down
2 changes: 1 addition & 1 deletion unittest/cppadcg-basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
// compile source code
DynamicModelLibraryProcessor<double> p(libcgen);

GccCompiler<double> compiler;
GccCompiler<double> compiler(PINOCCHIO_CXX_COMPILER);
std::unique_ptr<DynamicLib<double>> dynamicLib = p.createDynamicLibrary(compiler);

// save to files (not really required)
Expand Down
6 changes: 3 additions & 3 deletions unittest/cppadcg-joint-configurations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//Integrate
CodeGenIntegrate<double> cg_integrate(model);
cg_integrate.initLib();
cg_integrate.loadLib();
cg_integrate.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

cg_integrate.evalFunction(q1,v, results_q[0]);
pinocchio::integrate(model, q1,v,results_q[1]);
Expand All @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//Difference
CodeGenDifference<double> cg_difference(model);
cg_difference.initLib();
cg_difference.loadLib();
cg_difference.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

cg_difference.evalFunction(q1,q2, results_v[0]);
pinocchio::difference(model,q1,q2,results_v[1]);
Expand All @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(test_joint_configuration_code_generation)
//dDifference
CodeGenDDifference<double> cg_dDifference(model);
cg_dDifference.initLib();
cg_dDifference.loadLib();
cg_dDifference.compileAndLoadLib(PINOCCHIO_CXX_COMPILER);

//ARG0
std::vector<Eigen::MatrixXd> results_J(2,Eigen::MatrixXd::Zero(model.nv,model.nv));
Expand Down

0 comments on commit acaec06

Please sign in to comment.