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
Stack Of Tasks
eigenpy
Commits
a4ba7e8f
Verified
Commit
a4ba7e8f
authored
4 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
test: add test for user types
parent
fe2240da
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
+2
-0
2 additions, 0 deletions
unittest/CMakeLists.txt
unittest/python/test_user_type.py
+31
-0
31 additions, 0 deletions
unittest/python/test_user_type.py
unittest/user_type.cpp
+115
-0
115 additions, 0 deletions
unittest/user_type.cpp
with
148 additions
and
0 deletions
unittest/CMakeLists.txt
+
2
−
0
View file @
a4ba7e8f
...
@@ -36,12 +36,14 @@ ADD_LIB_UNIT_TEST(return_by_ref "eigen3")
...
@@ -36,12 +36,14 @@ ADD_LIB_UNIT_TEST(return_by_ref "eigen3")
IF
(
NOT
${
EIGEN3_VERSION
}
VERSION_LESS
"3.2.0"
)
IF
(
NOT
${
EIGEN3_VERSION
}
VERSION_LESS
"3.2.0"
)
ADD_LIB_UNIT_TEST
(
eigen_ref
"eigen3"
)
ADD_LIB_UNIT_TEST
(
eigen_ref
"eigen3"
)
ENDIF
()
ENDIF
()
ADD_LIB_UNIT_TEST
(
user_type
"eigen3"
)
ADD_PYTHON_UNIT_TEST
(
"py-matrix"
"unittest/python/test_matrix.py"
"unittest"
)
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-geometry"
"unittest/python/test_geometry.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-complex"
"unittest/python/test_complex.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-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-eigen-ref"
"unittest/python/test_eigen_ref.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-user-type"
"unittest/python/test_user_type.py"
"unittest"
)
ADD_PYTHON_UNIT_TEST
(
"py-switch"
"unittest/python/test_switch.py"
"python/eigenpy"
)
ADD_PYTHON_UNIT_TEST
(
"py-switch"
"unittest/python/test_switch.py"
"python/eigenpy"
)
SET_TESTS_PROPERTIES
(
"py-switch"
PROPERTIES DEPENDS
${
PYWRAP
}
)
SET_TESTS_PROPERTIES
(
"py-switch"
PROPERTIES DEPENDS
${
PYWRAP
}
)
...
...
This diff is collapsed.
Click to expand it.
unittest/python/test_user_type.py
0 → 100644
+
31
−
0
View file @
a4ba7e8f
import
user_type
rows
=
10
cols
=
20
def
test
(
mat
):
mat
.
fill
(
mat
.
dtype
.
type
(
10.
))
mat_copy
=
mat
.
copy
()
assert
(
mat
==
mat_copy
).
all
()
assert
not
(
mat
!=
mat_copy
).
all
()
mat_op
=
mat
+
mat
mat_op
=
mat
.
copy
(
order
=
'
F
'
)
+
mat
.
copy
(
order
=
'
C
'
)
mat_op
=
mat
-
mat
mat_op
=
mat
*
mat
mat_op
=
mat
.
dot
(
mat
.
T
)
mat_op
=
mat
/
mat
mat_op
=
-
mat
;
assert
(
mat
>=
mat
).
all
()
assert
(
mat
<=
mat
).
all
()
assert
not
(
mat
>
mat
).
all
()
assert
not
(
mat
<
mat
).
all
()
mat
=
user_type
.
create_double
(
rows
,
cols
)
test
(
mat
)
mat
=
user_type
.
create_float
(
rows
,
cols
)
test
(
mat
)
This diff is collapsed.
Click to expand it.
unittest/user_type.cpp
0 → 100644
+
115
−
0
View file @
a4ba7e8f
/*
* Copyright 2020 INRIA
*/
#include
"eigenpy/eigenpy.hpp"
#include
"eigenpy/user-type.hpp"
#include
"eigenpy/ufunc.hpp"
#include
<iostream>
#include
<sstream>
template
<
typename
Scalar
>
struct
CustomType
{
CustomType
()
{}
explicit
CustomType
(
const
Scalar
&
value
)
:
m_value
(
value
)
{}
CustomType
operator
*
(
const
CustomType
&
other
)
const
{
return
CustomType
(
m_value
*
other
.
m_value
);
}
CustomType
operator
+
(
const
CustomType
&
other
)
const
{
return
CustomType
(
m_value
+
other
.
m_value
);
}
CustomType
operator
-
(
const
CustomType
&
other
)
const
{
return
CustomType
(
m_value
-
other
.
m_value
);
}
CustomType
operator
/
(
const
CustomType
&
other
)
const
{
return
CustomType
(
m_value
/
other
.
m_value
);
}
void
operator
+=
(
const
CustomType
&
other
)
{
m_value
+=
other
.
m_value
;
}
void
operator
-=
(
const
CustomType
&
other
)
{
m_value
-=
other
.
m_value
;
}
void
operator
*=
(
const
CustomType
&
other
)
{
m_value
*=
other
.
m_value
;
}
void
operator
/=
(
const
CustomType
&
other
)
{
m_value
/=
other
.
m_value
;
}
void
operator
=
(
const
Scalar
&
value
)
{
m_value
=
value
;
}
bool
operator
==
(
const
CustomType
&
other
)
const
{
return
m_value
==
other
.
m_value
;
}
bool
operator
!=
(
const
CustomType
&
other
)
const
{
return
m_value
!=
other
.
m_value
;
}
bool
operator
<=
(
const
CustomType
&
other
)
const
{
return
m_value
<=
other
.
m_value
;
}
bool
operator
<
(
const
CustomType
&
other
)
const
{
return
m_value
<
other
.
m_value
;
}
bool
operator
>=
(
const
CustomType
&
other
)
const
{
return
m_value
>=
other
.
m_value
;
}
bool
operator
>
(
const
CustomType
&
other
)
const
{
return
m_value
>
other
.
m_value
;
}
CustomType
operator
-
()
const
{
return
CustomType
(
-
m_value
);
}
std
::
string
print
()
const
{
std
::
stringstream
ss
;
ss
<<
"value: "
<<
m_value
<<
std
::
endl
;
return
ss
.
str
();
}
protected
:
Scalar
m_value
;
};
template
<
typename
Scalar
>
Eigen
::
Matrix
<
CustomType
<
Scalar
>
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
create
(
int
rows
,
int
cols
)
{
typedef
Eigen
::
Matrix
<
CustomType
<
Scalar
>
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
Matrix
;
return
Matrix
(
rows
,
cols
);
}
template
<
typename
Scalar
>
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
build_matrix
(
int
rows
,
int
cols
)
{
typedef
Eigen
::
Matrix
<
Scalar
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
Matrix
;
return
Matrix
(
rows
,
cols
);
}
template
<
typename
Scalar
>
void
expose_custom_type
(
const
std
::
string
&
name
)
{
using
namespace
Eigen
;
namespace
bp
=
boost
::
python
;
typedef
CustomType
<
Scalar
>
Type
;
bp
::
class_
<
Type
>
(
name
.
c_str
(),
bp
::
init
<
Scalar
>
(
bp
::
arg
(
"value"
)))
.
def
(
bp
::
self
+
bp
::
self
)
.
def
(
bp
::
self
-
bp
::
self
)
.
def
(
bp
::
self
*
bp
::
self
)
.
def
(
bp
::
self
/
bp
::
self
)
.
def
(
bp
::
self
+=
bp
::
self
)
.
def
(
bp
::
self
-=
bp
::
self
)
.
def
(
bp
::
self
*=
bp
::
self
)
.
def
(
bp
::
self
/=
bp
::
self
)
.
def
(
"__repr__"
,
&
Type
::
print
)
;
eigenpy
::
registerNewType
<
Type
>
();
eigenpy
::
registerCommonUfunc
<
Type
>
();
}
BOOST_PYTHON_MODULE
(
user_type
)
{
using
namespace
Eigen
;
namespace
bp
=
boost
::
python
;
eigenpy
::
enableEigenPy
();
expose_custom_type
<
double
>
(
"CustomDouble"
);
typedef
CustomType
<
double
>
DoubleType
;
typedef
Eigen
::
Matrix
<
DoubleType
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
DoubleMatrix
;
eigenpy
::
EigenToPyConverter
<
DoubleMatrix
>::
registration
();
bp
::
def
(
"create_double"
,
create
<
double
>
);
expose_custom_type
<
float
>
(
"CustomFloat"
);
typedef
CustomType
<
float
>
FloatType
;
typedef
Eigen
::
Matrix
<
FloatType
,
Eigen
::
Dynamic
,
Eigen
::
Dynamic
>
FloatMatrix
;
eigenpy
::
EigenToPyConverter
<
FloatMatrix
>::
registration
();
bp
::
def
(
"create_float"
,
create
<
float
>
);
bp
::
def
(
"build_matrix"
,
build_matrix
<
double
>
);
}
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