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
bbb129d3
Verified
Commit
bbb129d3
authored
Apr 19, 2022
by
Justin Carpentier
Browse files
test: add more test for Eigen::Ref
parent
cd361037
Pipeline
#18398
passed with stage
in 10 minutes and 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
unittest/eigen_ref.cpp
View file @
bbb129d3
...
...
@@ -30,6 +30,13 @@ void setOnes(Eigen::Ref<MatType> mat) {
mat
.
setOnes
();
}
template
<
typename
MatType
>
Eigen
::
Ref
<
MatType
>
getBlock
(
Eigen
::
Ref
<
MatType
>
mat
,
Eigen
::
DenseIndex
i
,
Eigen
::
DenseIndex
j
,
Eigen
::
DenseIndex
n
,
Eigen
::
DenseIndex
m
)
{
return
mat
.
block
(
i
,
j
,
n
,
m
);
}
template
<
typename
MatType
>
void
fill
(
Eigen
::
Ref
<
MatType
>
mat
,
const
typename
MatType
::
Scalar
&
value
)
{
mat
.
fill
(
value
);
...
...
@@ -90,6 +97,8 @@ BOOST_PYTHON_MODULE(eigen_ref) {
bp
::
def
(
"asConstRef"
,
(
const
Eigen
::
Ref
<
const
MatrixXd
>
(
*
)(
Eigen
::
Ref
<
MatrixXd
>
))
asConstRef
<
MatrixXd
>
);
bp
::
def
(
"getBlock"
,
&
getBlock
<
MatrixXd
>
);
bp
::
class_
<
modify_wrap
,
boost
::
noncopyable
>
(
"modify_block"
,
bp
::
init
<>
())
.
def_readonly
(
"J"
,
&
modify_block
::
J
)
.
def
(
"modify"
,
&
modify_block
::
modify
)
...
...
unittest/python/test_eigen_ref.py
View file @
bbb129d3
...
...
@@ -22,8 +22,25 @@ def test(mat):
assert
np
.
all
(
ref
==
mat
)
const_ref
=
asConstRef
(
mat
)
# import pdb; pdb.set_trace()
assert
np
.
all
(
const_ref
==
mat
)
mat
.
fill
(
0.0
)
fill
(
mat
[:
3
,
:
2
],
1.0
)
assert
np
.
all
(
mat
[:
3
,
:
2
]
==
np
.
ones
((
3
,
2
)))
mat
.
fill
(
0.0
)
fill
(
mat
[:
2
,
:
3
],
1.0
)
assert
np
.
all
(
mat
[:
2
,
:
3
]
==
np
.
ones
((
2
,
3
)))
mat
.
fill
(
0.0
)
mat_as_C_order
=
np
.
array
(
mat
,
order
=
"F"
)
getBlock
(
mat_as_C_order
,
0
,
0
,
3
,
2
)[:,
:]
=
1.0
assert
np
.
all
(
mat_as_C_order
[:
3
,
:
2
]
==
np
.
ones
((
3
,
2
)))
class
ModifyBlockImpl
(
modify_block
):
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -32,12 +49,9 @@ def test(mat):
mat
[:,
:]
=
1.0
modify
=
ModifyBlockImpl
()
print
(
"Field J init:
\n
{}"
.
format
(
modify
.
J
))
modify
.
modify
(
2
,
3
)
print
(
"Field J after:
\n
{}"
.
format
(
modify
.
J
))
Jref
=
np
.
zeros
((
10
,
10
))
Jref
[:
2
,
:
3
]
=
1.0
print
(
"Should be:
\n
{}"
.
format
(
Jref
))
assert
np
.
array_equal
(
Jref
,
modify
.
J
)
...
...
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