-
Notifications
You must be signed in to change notification settings - Fork 44
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 #8 from dfki-ric/refactor/cleanup_cython
Clean up cython module
- Loading branch information
Showing
14 changed files
with
1,077 additions
and
555 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,26 @@ | ||
from functools import partial | ||
import numpy as np | ||
from movement_primitives.dmp import CartesianDMP | ||
import timeit | ||
|
||
|
||
start_y = np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) | ||
goal_y = np.array([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) | ||
dt = 0.01 | ||
int_dt = 0.001 | ||
|
||
dmp = CartesianDMP(execution_time=1.0, dt=dt, n_weights_per_dim=6, int_dt=int_dt) | ||
dmp.configure(start_y=start_y, goal_y=goal_y) | ||
dmp.set_weights(1000 * np.random.randn(*dmp.get_weights().shape)) | ||
|
||
times = timeit.repeat(partial(dmp.open_loop, quaternion_step_function="cython"), repeat=10, number=1) | ||
print("RK4 + Cython") | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) | ||
|
||
times = timeit.repeat(partial(dmp.open_loop, quaternion_step_function="python"), repeat=10, number=1) | ||
print("RK4 + Python") | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) | ||
|
||
times = timeit.repeat(partial(dmp.open_loop, step_function="euler", quaternion_step_function="python"), repeat=10, number=1) | ||
print("Euler + Python") | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) |
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,16 @@ | ||
from functools import partial | ||
import numpy as np | ||
from movement_primitives.dmp._canonical_system import canonical_system_alpha | ||
from movement_primitives.dmp._canonical_system import phase as phase_python | ||
from movement_primitives.dmp_fast import phase as phase_cython | ||
import timeit | ||
|
||
|
||
goal_t = 1.0 | ||
start_t = 0.0 | ||
int_dt = 0.001 | ||
alpha = canonical_system_alpha(0.01, goal_t, start_t, int_dt) | ||
times = timeit.repeat(partial(phase_python, 0.5, alpha, goal_t, start_t, int_dt), repeat=1000, number=1000) | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) | ||
times = timeit.repeat(partial(phase_cython, 0.5, alpha, goal_t, start_t, int_dt), repeat=1000, number=1000) | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) |
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
from functools import partial | ||
import numpy as np | ||
from movement_primitives.dmp import DualCartesianDMP | ||
import timeit | ||
|
||
|
||
start_y = np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]) | ||
goal_y = np.array([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]) | ||
dt = 0.001 | ||
int_dt = 0.0001 | ||
dt = 0.01 | ||
int_dt = 0.001 | ||
|
||
dmp = DualCartesianDMP(execution_time=1.0, dt=dt, n_weights_per_dim=6, int_dt=int_dt) | ||
dmp.configure(start_y=start_y, goal_y=goal_y) | ||
dmp.forcing_term.weights = 1000 * np.random.randn(*dmp.forcing_term.weights.shape) | ||
dmp.set_weights(1000 * np.random.randn(*dmp.get_weights().shape)) | ||
|
||
times = timeit.repeat(dmp.open_loop, repeat=10, number=1) | ||
times = timeit.repeat(partial(dmp.open_loop, step_function="cython"), repeat=10, number=1) | ||
print("Cython") | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) | ||
|
||
times = timeit.repeat(partial(dmp.open_loop, step_function="python"), repeat=10, number=1) | ||
print("Python") | ||
print("Mean: %.5f; Std. dev.: %.5f" % (np.mean(times), np.std(times))) | ||
# Pure python | ||
# Mean: 0.58188; Std. dev.: 0.00225 |
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
Oops, something went wrong.