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
81391d26
Commit
81391d26
authored
Apr 19, 2022
by
Wilson Jallet
🎬
Browse files
unittest: add test where block is edited from C++ function
isolates problem with conversion
parent
bbb129d3
Changes
2
Hide whitespace changes
Inline
Side-by-side
unittest/eigen_ref.cpp
View file @
81391d26
...
...
@@ -37,6 +37,16 @@ Eigen::Ref<MatType> getBlock(Eigen::Ref<MatType> mat, Eigen::DenseIndex i,
return
mat
.
block
(
i
,
j
,
n
,
m
);
}
template
<
typename
MatType
>
Eigen
::
Ref
<
MatType
>
editBlock
(
Eigen
::
Ref
<
MatType
>
mat
,
Eigen
::
DenseIndex
i
,
Eigen
::
DenseIndex
j
,
Eigen
::
DenseIndex
n
,
Eigen
::
DenseIndex
m
)
{
auto
B
=
mat
.
block
(
i
,
j
,
n
,
m
);
Eigen
::
Map
<
VectorXd
>
view
(
B
.
data
(),
B
.
size
());
view
.
setLinSpaced
(
1.
,
(
double
)
view
.
size
());
return
mat
;
}
template
<
typename
MatType
>
void
fill
(
Eigen
::
Ref
<
MatType
>
mat
,
const
typename
MatType
::
Scalar
&
value
)
{
mat
.
fill
(
value
);
...
...
@@ -98,6 +108,7 @@ BOOST_PYTHON_MODULE(eigen_ref) {
Eigen
::
Ref
<
MatrixXd
>
))
asConstRef
<
MatrixXd
>
);
bp
::
def
(
"getBlock"
,
&
getBlock
<
MatrixXd
>
);
bp
::
def
(
"editBlock"
,
&
editBlock
<
MatrixXd
>
);
bp
::
class_
<
modify_wrap
,
boost
::
noncopyable
>
(
"modify_block"
,
bp
::
init
<>
())
.
def_readonly
(
"J"
,
&
modify_block
::
J
)
...
...
unittest/python/test_eigen_ref.py
View file @
81391d26
...
...
@@ -37,10 +37,16 @@ def test(mat):
mat
.
fill
(
0.0
)
mat_as_C_order
=
np
.
array
(
mat
,
order
=
"F"
)
mat_copy
=
mat_as_C_order
.
copy
()
getBlock
(
mat_as_C_order
,
0
,
0
,
3
,
2
)[:,
:]
=
1.0
assert
np
.
all
(
mat_as_C_order
[:
3
,
:
2
]
==
np
.
ones
((
3
,
2
)))
editBlock
(
mat_as_C_order
,
0
,
0
,
3
,
2
)
mat_copy
[:
3
,
:
2
]
=
np
.
arange
(
6
).
reshape
(
3
,
2
)
assert
np
.
all
(
mat_as_C_order
==
mat_copy
)
class
ModifyBlockImpl
(
modify_block
):
def
__init__
(
self
):
super
().
__init__
()
...
...
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