Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
pinocchio
Commits
16f686ab
Verified
Commit
16f686ab
authored
Dec 14, 2019
by
Justin Carpentier
Browse files
serialization: add serialization of Eigen::Tensor
parent
add17ba7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/serialization/eigen.hpp
View file @
16f686ab
...
...
@@ -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
);
}
}
}
...
...
unittest/serialization.cpp
View file @
16f686ab
...
...
@@ -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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment