Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eigenpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guilhem Saurel
eigenpy
Commits
0d0b9a13
Verified
Commit
0d0b9a13
authored
5 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
test: add test of complex types
parent
7c81b8a9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
unittest/CMakeLists.txt
+3
-1
3 additions, 1 deletion
unittest/CMakeLists.txt
unittest/complex.cpp
+79
-0
79 additions, 0 deletions
unittest/complex.cpp
unittest/python/test_complex.py
+31
-0
31 additions, 0 deletions
unittest/python/test_complex.py
with
113 additions
and
1 deletion
unittest/CMakeLists.txt
+
3
−
1
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
}
)
...
...
This diff is collapsed.
Click to expand it.
unittest/complex.cpp
0 → 100644
+
79
−
0
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
>
);
}
This diff is collapsed.
Click to expand it.
unittest/python/test_complex.py
0 → 100644
+
31
−
0
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment