12 #include <boost/test/unit_test.hpp>
13 #include <boost/utility/binary.hpp>
15 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
19 using namespace CppAD;
22 typedef CG<double> CGD;
30 CppAD::vector<ADCG>
x(2);
36 CppAD::vector<ADCG>
y(1);
39 ADCG
a =
x[0] / 1. +
x[1] *
x[1];
58 LanguageC<double>
langC(
"double");
59 LangCDefaultVariableNameGenerator<double>
nameGen;
61 std::ostringstream
code;
63 std::cout <<
code.str();
68 typedef CppAD::cg::CG<double> CGD;
69 typedef CppAD::AD<CGD> ADCG;
71 typedef Eigen::Matrix<ADCG, Eigen::Dynamic, 1> ADCGVector;
73 ADCGVector vec_zero(ADCGVector::Zero(100));
74 BOOST_CHECK(vec_zero.isZero());
76 ADCGVector vec_ones(10);
77 vec_ones.fill((ADCG)1);
78 BOOST_CHECK(vec_ones.isOnes());
87 ADCGVector vec_nan(10);
88 vec_nan.fill((ADCG)NAN);
93 ADCG val_minus_one(-1.);
94 ADCG val_abs(abs(val_minus_one));
95 ADCGVector vec_minus_one(10);
96 vec_minus_one.fill(val_minus_one);
97 vec_minus_one.array().abs();
99 BOOST_CHECK(!vec_ones.isUnitary());
104 typedef CppAD::cg::CG<double> CGScalar;
105 typedef CppAD::AD<double> ADScalar;
106 typedef CppAD::AD<float> ADFloat;
112 CGSE3 cg_M =
M.cast<CGScalar>();
113 BOOST_CHECK(cg_M.cast<
double>().isApprox(
M));
117 BOOST_CHECK(
axis.isUnitary());
132 CPPAD_TESTVECTOR(ADScalar) ad_x(3);
133 CGJointModelPrismaticUnaligned cg_jmodel_prismatic(
axis.cast<CGScalar>());
138 CGModel cg_model =
model.cast<CGScalar>();
141 CppAD::AD<double> ad_value(-1.);
144 CppAD::cg::CG<double> cg_value(-1.);
152 using namespace CppAD;
156 typedef CG<double> CGD;
157 typedef AD<CGD> ADCG;
159 typedef AD<double> ADScalar;
166 std::vector<ADCG>
x(2);
170 std::vector<ADCG>
y(1);
173 ADCG
a =
x[0] / 1. +
x[1] *
x[1];
176 ADFun<CGD>
fun(
x,
y);
183 ModelCSourceGen<double> cgen(
fun,
"model");
184 cgen.setCreateJacobian(
true);
185 cgen.setCreateForwardOne(
true);
186 cgen.setCreateReverseOne(
true);
187 cgen.setCreateReverseTwo(
true);
188 ModelLibraryCSourceGen<double> libcgen(cgen);
191 DynamicModelLibraryProcessor<double>
p(libcgen);
193 GccCompiler<double> compiler(PINOCCHIO_CXX_COMPILER);
194 std::unique_ptr<DynamicLib<double>> dynamicLib =
p.createDynamicLibrary(compiler);
197 SaveFilesModelLibraryProcessor<double> p2(libcgen);
204 std::unique_ptr<GenericModel<double>>
model = dynamicLib->model(
"model");
205 CPPAD_TESTVECTOR(
double) xv(
x.size());
208 CPPAD_TESTVECTOR(
double)
jac =
model->Jacobian(xv);
210 std::vector<ADScalar> x_ad(2);
214 std::vector<ADScalar> y_ad(1);
217 ADScalar a_ad = x_ad[0] / 1. + x_ad[1] * x_ad[1];
220 ADFun<double> ad_fun(x_ad, y_ad);
222 CPPAD_TESTVECTOR(
double) jac_ref = ad_fun.Jacobian(xv);
225 std::cout <<
jac[0] <<
" " <<
jac[1] << std::endl;
228 Eigen::Map<Eigen::Vector2d>(
jac.data()).isApprox(Eigen::Map<Eigen::Vector2d>(jac_ref.data())));
231 BOOST_AUTO_TEST_SUITE_END()