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
cd6e8a48
Commit
cd6e8a48
authored
10 years ago
by
Nicolas Mansard
Committed by
nmansard
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convertion from Eigen to Numpy::Matrix.
parent
211ab1b2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/test_unit.py
+4
-4
4 additions, 4 deletions
python/test_unit.py
src/eigenpy.hpp
+26
-10
26 additions, 10 deletions
src/eigenpy.hpp
with
30 additions
and
14 deletions
python/test_unit.py
+
4
−
4
View file @
cd6e8a48
...
@@ -5,7 +5,7 @@ verbose = False
...
@@ -5,7 +5,7 @@ verbose = False
if
verbose
:
print
"
===> From MatrixXd to Py
"
if
verbose
:
print
"
===> From MatrixXd to Py
"
M
=
eigenpy
.
naturals
(
3
,
3
,
verbose
)
M
=
eigenpy
.
naturals
(
3
,
3
,
verbose
)
Mcheck
=
np
.
reshape
(
np
.
array
(
range
(
9
),
np
.
double
),[
3
,
3
])
Mcheck
=
np
.
reshape
(
np
.
matrix
(
range
(
9
),
np
.
double
),[
3
,
3
])
assert
np
.
array_equal
(
Mcheck
,
M
)
assert
np
.
array_equal
(
Mcheck
,
M
)
if
verbose
:
print
"
===> From Matrix3d to Py
"
if
verbose
:
print
"
===> From Matrix3d to Py
"
...
@@ -14,13 +14,13 @@ assert np.array_equal(Mcheck,M33)
...
@@ -14,13 +14,13 @@ assert np.array_equal(Mcheck,M33)
if
verbose
:
print
"
===> From VectorXd to Py
"
if
verbose
:
print
"
===> From VectorXd to Py
"
v
=
eigenpy
.
naturalsX
(
3
,
verbose
)
v
=
eigenpy
.
naturalsX
(
3
,
verbose
)
vcheck
=
np
.
array
([
range
(
3
),],
np
.
double
).
T
vcheck
=
np
.
matrix
([
range
(
3
),],
np
.
double
).
T
assert
np
.
array_equal
(
vcheck
,
v
)
assert
np
.
array_equal
(
vcheck
,
v
)
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
if
verbose
:
print
"
===> From Py to Eigen::MatrixXd
"
Mref
=
np
.
reshape
(
np
.
array
(
range
(
64
),
np
.
double
),[
8
,
8
])
Mref
=
np
.
reshape
(
np
.
matrix
(
range
(
64
),
np
.
double
),[
8
,
8
])
if
verbose
:
print
"
===> Matrix 8x8
"
if
verbose
:
print
"
===> Matrix 8x8
"
M
=
Mref
M
=
Mref
...
@@ -68,7 +68,7 @@ if verbose: print "===> From Py to Eigen::VectorXd"
...
@@ -68,7 +68,7 @@ if verbose: print "===> From Py to Eigen::VectorXd"
if
verbose
:
print
"
===> Block Vector 0:6:2x1 1 dim
"
if
verbose
:
print
"
===> Block Vector 0:6:2x1 1 dim
"
M
=
Mref
[
0
:
6
:
2
,
1
].
T
M
=
Mref
[
0
:
6
:
2
,
1
].
T
assert
(
np
.
array_equal
(
np
.
array
([
M
,])
.
T
,
eigenpy
.
reflexV
(
M
,
verbose
))
);
assert
(
np
.
array_equal
(
M
.
T
,
eigenpy
.
reflexV
(
M
,
verbose
))
);
if
verbose
:
print
"
===> Block Vector 0:6:2x1
"
if
verbose
:
print
"
===> Block Vector 0:6:2x1
"
M
=
Mref
[
0
:
6
:
2
,
1
:
2
]
M
=
Mref
[
0
:
6
:
2
,
1
:
2
]
...
...
This diff is collapsed.
Click to expand it.
src/eigenpy.hpp
+
26
−
10
View file @
cd6e8a48
...
@@ -42,6 +42,31 @@ namespace eigenpy
...
@@ -42,6 +42,31 @@ namespace eigenpy
template
<
>
struct
NumpyEquivalentType
<
int
>
{
enum
{
type_code
=
NPY_INT
};};
template
<
>
struct
NumpyEquivalentType
<
int
>
{
enum
{
type_code
=
NPY_INT
};};
template
<
>
struct
NumpyEquivalentType
<
float
>
{
enum
{
type_code
=
NPY_FLOAT
};};
template
<
>
struct
NumpyEquivalentType
<
float
>
{
enum
{
type_code
=
NPY_FLOAT
};};
struct
PyMatrixType
{
boost
::
python
::
object
pyMatrixType
;
boost
::
python
::
object
pyModule
;
PyMatrixType
()
{
pyModule
=
boost
::
python
::
import
(
"numpy"
);
pyMatrixType
=
pyModule
.
attr
(
"matrix"
);
}
operator
boost
::
python
::
object
()
{
return
pyMatrixType
;
}
boost
::
python
::
object
make
(
PyArrayObject
*
pyArray
,
bool
copy
=
false
)
{
return
make
((
PyObject
*
)
pyArray
,
copy
);
}
boost
::
python
::
object
make
(
PyObject
*
pyObj
,
bool
copy
=
false
)
{
boost
::
python
::
object
m
=
pyMatrixType
(
boost
::
python
::
object
(
boost
::
python
::
handle
<>
(
pyObj
)),
boost
::
python
::
object
(),
copy
);
Py_INCREF
(
m
.
ptr
());
return
m
;
}
};
static
PyMatrixType
pyMatrixType
=
PyMatrixType
();
/* --- TO PYTHON -------------------------------------------------------------- */
/* --- TO PYTHON -------------------------------------------------------------- */
template
<
typename
MatType
,
typename
EquivalentEigenType
>
template
<
typename
MatType
,
typename
EquivalentEigenType
>
...
@@ -60,15 +85,7 @@ namespace eigenpy
...
@@ -60,15 +85,7 @@ namespace eigenpy
MapNumpy
<
EquivalentEigenType
>::
map
(
pyArray
)
=
mat
;
MapNumpy
<
EquivalentEigenType
>::
map
(
pyArray
)
=
mat
;
return
pyMatrixType
.
make
(
pyArray
).
ptr
();
boost
::
python
::
object
pyModule
=
boost
::
python
::
import
(
"numpy"
);
boost
::
python
::
object
pyMatrixType
=
pyModule
.
attr
(
"matrix"
);
boost
::
python
::
object
m
=
pyMatrixType
(
boost
::
python
::
object
(
boost
::
python
::
handle
<>
((
PyObject
*
)
pyArray
)),
boost
::
python
::
object
(),
true
);
Py_INCREF
(
m
.
ptr
());
return
m
.
ptr
();
}
}
};
};
...
@@ -198,5 +215,4 @@ namespace eigenpy
...
@@ -198,5 +215,4 @@ namespace eigenpy
}
}
}
// namespace eigenpy
}
// namespace eigenpy
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