Verified Commit 16f686ab authored by Justin Carpentier's avatar Justin Carpentier
Browse files

serialization: add serialization of Eigen::Tensor

parent add17ba7
......@@ -82,6 +82,34 @@ namespace boost
{
split_free(ar,a,version);
}
template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
void save(Archive & ar, const ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int /*version*/)
{
typedef ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> Tensor;
const typename Tensor::Dimensions & dimensions = t.dimensions();
ar & BOOST_SERIALIZATION_NVP(dimensions);
ar & make_nvp("data",make_array(t.data(), (size_t)t.size()));
}
template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
void load(Archive & ar, ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int /*version*/)
{
typedef ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> Tensor;
typename Tensor::Dimensions dimensions;
ar >> BOOST_SERIALIZATION_NVP(dimensions);
t.resize(dimensions);
ar >> make_nvp("data",make_array(t.data(), (size_t)t.size()));
}
template <class Archive, typename _Scalar, int _NumIndices, int _Options, typename _IndexType>
void serialize(Archive & ar, ::pinocchio::Tensor<_Scalar,_NumIndices,_Options,_IndexType> & t, const unsigned int version)
{
split_free(ar,t,version);
}
}
}
......
......@@ -106,7 +106,17 @@ BOOST_AUTO_TEST_CASE(test_eigen_serialization)
generic_test(Vec,TEST_SERIALIZATION_FOLDER"/eigen_vector","vector");
Eigen::array<Eigen::DenseIndex,array_size> array = { 1, 2, 3 };
generic_test(array,TEST_SERIALIZATION_FOLDER"/eigen_array","ar");
generic_test(array,TEST_SERIALIZATION_FOLDER"/eigen_array","array");
const Eigen::DenseIndex tensor_size = 3;
const Eigen::DenseIndex x_dim = 10, y_dim = 20, z_dim = 30;
typedef pinocchio::Tensor<double,tensor_size> Tensor3x;
Tensor3x tensor(x_dim,y_dim,z_dim);
Eigen::Map<Eigen::VectorXd>(tensor.data(),tensor.size(),1).setRandom();
generic_test(tensor,TEST_SERIALIZATION_FOLDER"/eigen_tensor","tensor");
}
BOOST_AUTO_TEST_CASE(test_spatial_serialization)
......@@ -313,7 +323,6 @@ BOOST_AUTO_TEST_CASE(test_throw_extension)
std::invalid_argument);
}
}
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment