5 #include "pinocchio/math/tensor.hpp" 6 #include "pinocchio/multibody/model.hpp" 8 #include <boost/test/unit_test.hpp> 9 #include <boost/utility/binary.hpp> 13 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
21 const Eigen::DenseIndex x_dim = 6, y_dim = 20, z_dim = 20;
22 Tensor tensor1(x_dim,y_dim,z_dim), tensor1_bis(x_dim,y_dim,z_dim);
24 BOOST_CHECK(tensor1.size() == x_dim * y_dim * z_dim);
25 BOOST_CHECK(tensor1.dimension(0) == x_dim);
26 BOOST_CHECK(tensor1.dimension(1) == y_dim);
27 BOOST_CHECK(tensor1.dimension(2) == z_dim);
29 Scalar *
data = tensor1.data();
30 for(Eigen::DenseIndex k = 0; k < tensor1.size(); ++k)
33 for(Eigen::DenseIndex k = 0; k < z_dim; ++k)
35 for(Eigen::DenseIndex j = 0; j < y_dim; ++j)
37 for(Eigen::DenseIndex
i = 0;
i < x_dim; ++
i)
39 BOOST_CHECK(tensor1(
i,j,k) == (Scalar)(
i + j*x_dim + k*(x_dim*y_dim)));
44 const Eigen::DenseIndex new_x_dim = 2*x_dim, new_y_dim = 2*y_dim, new_z_dim = 2*z_dim;
48 BOOST_CHECK(tensor1.size() == tensor1_bis.size());
49 for(std::size_t
i = 0;
i < rank; ++
i)
50 BOOST_CHECK(tensor1.dimension(
i) == dims[
i]);
53 tensor1.resize(new_dims);
55 BOOST_CHECK(tensor1.size() == 8*tensor1_bis.size());
56 for(std::size_t
i = 0;
i < rank; ++
i)
57 BOOST_CHECK(tensor1.dimension(
i) == new_dims[
i]);
60 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(test_emulate_tensors)