eigen-tensor.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019 INRIA
3 //
4 
7 
8 #include <boost/test/unit_test.hpp>
9 #include <boost/utility/binary.hpp>
10 
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
14 
15 BOOST_AUTO_TEST_CASE(test_emulate_tensors)
16 {
17  typedef double Scalar;
18  const int rank = 3;
19  typedef pinocchio::Tensor<Scalar, rank> Tensor;
20 
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);
23 
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);
28 
29  Scalar * data = tensor1.data();
30  for (Eigen::DenseIndex k = 0; k < tensor1.size(); ++k)
31  data[k] = (Scalar)k;
32 
33  for (Eigen::DenseIndex k = 0; k < z_dim; ++k)
34  {
35  for (Eigen::DenseIndex j = 0; j < y_dim; ++j)
36  {
37  for (Eigen::DenseIndex i = 0; i < x_dim; ++i)
38  {
39  BOOST_CHECK(tensor1(i, j, k) == (Scalar)(i + j * x_dim + k * (x_dim * y_dim)));
40  }
41  }
42  }
43 
44  const Eigen::DenseIndex new_x_dim = 2 * x_dim, new_y_dim = 2 * y_dim, new_z_dim = 2 * z_dim;
45  const Eigen::array<Tensor::Index, rank> dims = {x_dim, y_dim, z_dim};
46  tensor1.resize(dims);
47 
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]);
51 
52  const Eigen::array<Tensor::Index, rank> new_dims = {new_x_dim, new_y_dim, new_z_dim};
53  tensor1.resize(new_dims);
54 
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]);
58 }
59 
60 BOOST_AUTO_TEST_SUITE_END()
inverse-kinematics.i
int i
Definition: inverse-kinematics.py:17
model.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_emulate_tensors)
Definition: eigen-tensor.cpp:15
setup.data
data
Definition: cmake/cython/setup.in.py:48
pinocchio::python::Scalar
context::Scalar Scalar
Definition: admm-solver.cpp:29
Eigen::array
Definition: tensor.hpp:20
collision-with-point-clouds.x_dim
x_dim
Definition: collision-with-point-clouds.py:43
collision-with-point-clouds.y_dim
y_dim
Definition: collision-with-point-clouds.py:49
pinocchio::Tensor
Definition: tensor.hpp:103
tensor.hpp


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:43