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
eigenpy
Commits
0d0b9a13
Verified
Commit
0d0b9a13
authored
Jan 22, 2020
by
Justin Carpentier
Browse files
test: add test of complex types
parent
7c81b8a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
unittest/CMakeLists.txt
View file @
0d0b9a13
#
# Copyright (c) 2014-2019 CNRS
# Copyright (c) 2018-20
19
INRIA
# Copyright (c) 2018-20
20
INRIA
#
MACRO
(
ADD_LIB_UNIT_TEST test PKGS
)
...
...
@@ -31,12 +31,14 @@ ENDMACRO(ADD_LIB_UNIT_TEST)
ADD_LIB_UNIT_TEST
(
matrix
"eigen3"
)
ADD_LIB_UNIT_TEST
(
geometry
"eigen3"
)
ADD_LIB_UNIT_TEST
(
complex
"eigen3"
)
IF
(
NOT
${
EIGEN3_VERSION
}
VERSION_LESS
"3.2.0"
)
ADD_LIB_UNIT_TEST
(
ref
"eigen3"
)
ENDIF
()
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-switch"
"unittest/python/test_switch.py"
"python/eigenpy"
)
SET_TESTS_PROPERTIES
(
"py-switch"
PROPERTIES DEPENDS
${
PYWRAP
}
)
...
...
unittest/complex.cpp
0 → 100644
View file @
0d0b9a13
/*
* Copyright 2020 INRIA
*/
#include
"eigenpy/eigenpy.hpp"
namespace
Eigen
{
#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
/** \ingroup matrixtypedefs */
\
typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */
\
typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
/** \ingroup matrixtypedefs */
\
typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
/** \ingroup matrixtypedefs */
\
typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
/** \ingroup matrixtypedefs */
\
typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES
(
long
double
,
ld
)
EIGEN_MAKE_TYPEDEFS_ALL_SIZES
(
std
::
complex
<
long
double
>
,
cld
)
#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
#undef EIGEN_MAKE_TYPEDEFS
#undef EIGEN_MAKE_FIXED_TYPEDEFS
}
template
<
typename
ComplexMatrix
>
typename
Eigen
::
Matrix
<
typename
ComplexMatrix
::
RealScalar
,
ComplexMatrix
::
RowsAtCompileTime
,
ComplexMatrix
::
ColsAtCompileTime
,
ComplexMatrix
::
Options
>
real
(
const
Eigen
::
MatrixBase
<
ComplexMatrix
>
&
complex_mat
)
{
return
complex_mat
.
real
();
}
template
<
typename
ComplexMatrix
>
typename
Eigen
::
Matrix
<
typename
ComplexMatrix
::
RealScalar
,
ComplexMatrix
::
RowsAtCompileTime
,
ComplexMatrix
::
ColsAtCompileTime
,
ComplexMatrix
::
Options
>
imag
(
const
Eigen
::
MatrixBase
<
ComplexMatrix
>
&
complex_mat
)
{
return
complex_mat
.
imag
();
}
template
<
typename
Scalar
,
int
Rows
,
int
Cols
,
int
Options
>
Eigen
::
Matrix
<
std
::
complex
<
Scalar
>
,
Rows
,
Cols
,
Options
>
ascomplex
(
const
Eigen
::
Matrix
<
Scalar
,
Rows
,
Cols
,
Options
>
&
mat
)
{
typedef
Eigen
::
Matrix
<
std
::
complex
<
Scalar
>
,
Rows
,
Cols
,
Options
>
ReturnType
;
return
ReturnType
(
mat
);
}
BOOST_PYTHON_MODULE
(
complex
)
{
using
namespace
Eigen
;
namespace
bp
=
boost
::
python
;
eigenpy
::
enableEigenPy
();
bp
::
def
(
"ascomplex"
,
ascomplex
<
float
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
0
>
);
bp
::
def
(
"ascomplex"
,
ascomplex
<
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
0
>
);
bp
::
def
(
"ascomplex"
,
ascomplex
<
long
double
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
,
0
>
);
bp
::
def
(
"real"
,
(
MatrixXf
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcf
>
&
))
&
real
<
MatrixXcf
>
);
bp
::
def
(
"real"
,
(
MatrixXd
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcd
>
&
))
&
real
<
MatrixXcd
>
);
bp
::
def
(
"real"
,
(
MatrixXld
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcld
>
&
))
&
real
<
MatrixXcld
>
);
bp
::
def
(
"imag"
,
(
MatrixXf
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcf
>
&
))
&
imag
<
MatrixXcf
>
);
bp
::
def
(
"imag"
,
(
MatrixXd
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcd
>
&
))
&
imag
<
MatrixXcd
>
);
bp
::
def
(
"imag"
,
(
MatrixXld
(
*
)(
const
Eigen
::
MatrixBase
<
MatrixXcld
>
&
))
&
imag
<
MatrixXcld
>
);
}
unittest/python/test_complex.py
0 → 100644
View file @
0d0b9a13
from
__future__
import
print_function
import
numpy
as
np
from
complex
import
*
switchToNumpyArray
()
rows
=
10
cols
=
20
def
test
(
dtype
):
Z
=
np
.
zeros
((
rows
,
cols
),
dtype
=
dtype
)
Z
.
real
=
np
.
random
.
rand
(
rows
,
cols
)
Z
.
imag
=
np
.
random
.
rand
(
rows
,
cols
)
Z_real
=
real
(
Z
)
assert
(
Z_real
==
Z
.
real
).
all
()
Z_imag
=
imag
(
Z
)
assert
(
Z_imag
==
Z
.
imag
).
all
()
Y
=
np
.
ones
((
rows
,
cols
))
Y_complex
=
ascomplex
(
Y
)
assert
(
Y_complex
.
real
==
Y
).
all
()
assert
(
Y_complex
.
imag
==
np
.
zeros
((
rows
,
cols
))).
all
()
# Float
test
(
np
.
csingle
)
# Double
test
(
np
.
cdouble
)
# Long Double
test
(
np
.
clongdouble
)
Write
Preview
Supports
Markdown
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