-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from jcarpent/topic/conversion
Handle conversion from Eigen::Matrix to numpy.array or numpy.matrix
- Loading branch information
Showing
5 changed files
with
139 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import print_function | ||
|
||
import eigenpy | ||
import numpy as np | ||
|
||
import time | ||
import timeit | ||
|
||
from IPython import get_ipython | ||
ipython = get_ipython() | ||
|
||
quat = eigenpy.Quaternion() | ||
a = [0., 0., 0.] | ||
|
||
cmd1 = "timeit np.array(a)" | ||
print("\n") | ||
print(cmd1) | ||
ipython.magic(cmd1) | ||
print("\n") | ||
|
||
cmd2 = "timeit np.matrix(a)" | ||
print(cmd2) | ||
ipython.magic(cmd2) | ||
print("\n") | ||
|
||
eigenpy.switchToNumpyMatrix() | ||
print("----------------------") | ||
print("switch to numpy matrix") | ||
print("----------------------") | ||
print("\n") | ||
|
||
cmd3 = "timeit quat.coeffs()" | ||
print(cmd3) | ||
ipython.magic(cmd3) | ||
print("\n") | ||
|
||
eigenpy.switchToNumpyArray() | ||
print("---------------------") | ||
print("switch to numpy array") | ||
print("---------------------") | ||
print("\n") | ||
|
||
cmd4 = "timeit quat.coeffs()" | ||
print(cmd4) | ||
ipython.magic(cmd4) | ||
print("\n") | ||
|
||
cmd5 = "timeit np.asmatrix(quat.coeffs())" | ||
print(cmd5) | ||
ipython.magic(cmd5) | ||
print("\n") | ||
|
||
a_matrix = np.matrix(a); | ||
cmd6 = "timeit np.asarray(a_matrix)" | ||
print(cmd6) | ||
ipython.magic(cmd6) | ||
print("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import print_function | ||
|
||
import eigenpy | ||
import numpy as np | ||
|
||
quat = eigenpy.Quaternion() | ||
# By default, we convert as numpy.matrix | ||
coeffs_vector = quat.coeffs() | ||
print(type(coeffs_vector)) | ||
|
||
assert isinstance(coeffs_vector,np.matrixlib.defmatrix.matrix) | ||
|
||
# Switch to numpy.array | ||
eigenpy.switchToNumpyArray() | ||
coeffs_array = quat.coeffs() | ||
print(type(coeffs_array)) | ||
|
||
assert isinstance(coeffs_vector,np.ndarray) |