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
85e6bcd9
Verified
Commit
85e6bcd9
authored
Jul 30, 2021
by
Justin Carpentier
Browse files
test: enhance testing of user types
parent
ac74a487
Changes
2
Hide whitespace changes
Inline
Side-by-side
unittest/python/test_user_type.py
View file @
85e6bcd9
...
...
@@ -5,8 +5,8 @@ import numpy as np
rows
=
10
cols
=
20
def
test
(
mat
):
mat
[:]
=
mat
.
dtype
.
type
(
10.
)
def
test
(
dtype
):
mat
=
np
.
ones
((
rows
,
cols
),
dtype
=
d
type
)
mat_copy
=
mat
.
copy
()
assert
(
mat
==
mat_copy
).
all
()
assert
not
(
mat
!=
mat_copy
).
all
()
...
...
@@ -25,18 +25,31 @@ def test(mat):
mat_op
=
mat
.
dot
(
mat
.
T
)
mat_op
=
mat
/
mat
mat_op
=
-
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
)
def
test_cast
(
from_dtype
,
to_dtype
):
np
.
can_cast
(
from_dtype
,
to_dtype
)
mat
=
user_type
.
create_float
(
rows
,
cols
)
test
(
mat
)
from_mat
=
np
.
zeros
((
rows
,
cols
),
dtype
=
from_dtype
)
to_mat
=
from_mat
.
astype
(
dtype
=
to_dtype
)
test
(
user_type
.
CustomDouble
)
test_cast
(
user_type
.
CustomDouble
,
np
.
double
)
test_cast
(
np
.
double
,
user_type
.
CustomDouble
)
test_cast
(
user_type
.
CustomDouble
,
np
.
int64
)
test_cast
(
np
.
int64
,
user_type
.
CustomDouble
)
test_cast
(
user_type
.
CustomDouble
,
np
.
int32
)
test_cast
(
np
.
int32
,
user_type
.
CustomDouble
)
test
(
user_type
.
CustomFloat
)
v
=
user_type
.
CustomDouble
(
1
)
a
=
np
.
array
(
v
)
...
...
unittest/user_type.cpp
View file @
85e6bcd9
...
...
@@ -97,6 +97,11 @@ struct CustomType
CustomType
operator
-
()
const
{
return
CustomType
(
-
m_value
);
}
operator
Scalar
()
const
{
return
m_value
;
}
std
::
string
print
()
const
{
std
::
stringstream
ss
;
...
...
@@ -110,7 +115,7 @@ struct CustomType
return
os
;
}
protected:
//
protected:
Scalar
m_value
;
};
...
...
@@ -186,4 +191,16 @@ BOOST_PYTHON_MODULE(user_type)
bp
::
def
(
"build_matrix"
,
build_matrix
<
double
>
);
bp
::
def
(
"print"
,
print
<
double
>
);
bp
::
def
(
"print"
,
print
<
float
>
);
eigenpy
::
registerCast
<
DoubleType
,
double
>
(
true
);
eigenpy
::
registerCast
<
double
,
DoubleType
>
(
true
);
eigenpy
::
registerCast
<
DoubleType
,
int32_t
>
(
false
);
eigenpy
::
registerCast
<
int32_t
,
DoubleType
>
(
true
);
eigenpy
::
registerCast
<
DoubleType
,
int64_t
>
(
false
);
eigenpy
::
registerCast
<
int64_t
,
DoubleType
>
(
true
);
eigenpy
::
registerCast
<
FloatType
,
int64_t
>
(
false
);
eigenpy
::
registerCast
<
int64_t
,
FloatType
>
(
true
);
bp
::
implicitly_convertible
<
double
,
DoubleType
>
();
bp
::
implicitly_convertible
<
DoubleType
,
double
>
();
}
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