Skip to content
GitLab
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
eigenpy
Commits
9e606508
Verified
Commit
9e606508
authored
Feb 25, 2020
by
Justin Carpentier
Browse files
test: add test for Eigen::Ref
parent
1fe6a61c
Changes
3
Hide whitespace changes
Inline
Side-by-side
unittest/CMakeLists.txt
View file @
9e606508
...
...
@@ -42,6 +42,7 @@ ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
ADD_PYTHON_UNIT_TEST
(
"py-geometry"
"unittest/python/test_geometry.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-complex"
"unittest/python/test_complex.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-return-by-ref"
"unittest/python/test_return_by_ref.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-eigen-ref"
"unittest/python/test_eigen_ref.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-switch"
"unittest/python/test_switch.py"
"python/eigenpy"
)
SET_TESTS_PROPERTIES
(
"py-switch"
PROPERTIES DEPENDS
${
PYWRAP
}
)
...
...
unittest/eigen_ref.cpp
View file @
9e606508
...
...
@@ -10,7 +10,7 @@ using namespace Eigen;
using
namespace
eigenpy
;
template
<
typename
MatType
>
void
printMatrix
(
const
Eigen
::
Ref
<
MatType
>
&
mat
)
void
printMatrix
(
const
Eigen
::
Ref
<
const
MatType
>
mat
)
{
if
(
MatType
::
IsVectorAtCompileTime
)
std
::
cout
<<
"isVector"
<<
std
::
endl
;
...
...
@@ -19,7 +19,7 @@ void printMatrix(const Eigen::Ref<MatType> & mat)
}
template
<
typename
VecType
>
void
printVector
(
const
Eigen
::
Ref
<
VecType
>
&
vec
)
void
printVector
(
const
Eigen
::
Ref
<
const
VecType
>
&
vec
)
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY
(
VecType
);
printMatrix
(
vec
);
...
...
@@ -28,9 +28,13 @@ void printVector(const Eigen::Ref<VecType> & vec)
template
<
typename
MatType
>
void
setOnes
(
Eigen
::
Ref
<
MatType
>
mat
)
{
printMatrix
(
mat
);
mat
.
setOnes
();
printMatrix
(
mat
);
}
template
<
typename
MatType
>
void
fill
(
Eigen
::
Ref
<
MatType
>
mat
,
const
typename
MatType
::
Scalar
&
value
)
{
mat
.
fill
(
value
);
}
BOOST_PYTHON_MODULE
(
eigen_ref
)
...
...
@@ -48,4 +52,8 @@ BOOST_PYTHON_MODULE(eigen_ref)
bp
::
def
(
"setOnes"
,
setOnes
<
Vector3d
>
);
bp
::
def
(
"setOnes"
,
setOnes
<
VectorXd
>
);
bp
::
def
(
"setOnes"
,
setOnes
<
MatrixXd
>
);
bp
::
def
(
"fillVec3"
,
fill
<
Vector3d
>
);
bp
::
def
(
"fillVec"
,
fill
<
VectorXd
>
);
bp
::
def
(
"fill"
,
fill
<
MatrixXd
>
);
}
unittest/python/test_eigen_ref.py
0 → 100644
View file @
9e606508
import
numpy
as
np
from
eigen_ref
import
*
def
test
(
mat
):
printMatrix
(
mat
)
fill
(
mat
,
1.
)
printMatrix
(
mat
)
assert
np
.
array_equal
(
mat
,
np
.
full
(
mat
.
shape
,
1.
))
rows
=
10
cols
=
30
mat
=
np
.
array
(
np
.
zeros
((
rows
,
cols
)))
test
(
mat
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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