Created
May 8, 2021 13:29
-
-
Save alisterburt/4a32e9c122498ac0ab482ee5ba44ba10 to your computer and use it in GitHub Desktop.
benchmark eulerangles
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "7b27144d-a20f-40dc-be9b-350c4cb36f65", | |
"metadata": {}, | |
"source": [ | |
"# Benchmarking the `eulerangles` package" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "be584215-10bf-4a1e-a620-58f68fd567d1", | |
"metadata": {}, | |
"source": [ | |
"In this notebook we will benchmark the `eulerangles` package against `scipy.spatial.transform.Rotation`" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "75dbc236-f1e7-4d0e-b643-af3c22808c6c", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"from scipy.spatial.transform import Rotation as R\n", | |
"from eulerangles import euler2euler" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "e4235110-ad10-4467-ad1e-f76e14324b5e", | |
"metadata": {}, | |
"source": [ | |
"Generate a test set of a million euler triplets" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "c02208f0-3cfa-4776-ac0e-e40af9e33a7a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"eulers = np.random.uniform(low=0, high=180, size=(1000000, 3))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "8116eb33-fd9b-4de2-822f-f4566b05f394", | |
"metadata": {}, | |
"source": [ | |
"Define functions for benchmarking" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "5bbe7dbc-47d8-405f-9036-5edb5701b313", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def eulers_scipy():\n", | |
" # intrinsic rotation is defined implicitly by the case of the angle sequence\n", | |
"\t# no control over right handed vs. left handed rotations\n", | |
"\tglobal eulers\n", | |
"\trotations = R.from_euler('ZYZ', eulers, degrees=True)\n", | |
"\teulers_out = rotations.as_euler('ZXZ', degrees=True)\n", | |
"\treturn eulers_out\n", | |
"\n", | |
"def eulers_eulerangles():\n", | |
"\tglobal eulers\n", | |
"\treturn euler2euler(eulers, \n", | |
"\t\tsource_axes='ZYZ', source_intrinsic=True, source_right_handed_rotation=True,\n", | |
"\t\ttarget_axes='ZXZ', target_intrinsic=True, target_right_handed_rotation=True,\n", | |
"\t\tinvert_matrix=False\n", | |
" )" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "baf6d8e0-332e-4b20-956e-2a49e9dbd736", | |
"metadata": {}, | |
"source": [ | |
"Time execution" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "f408493d-f190-495d-808d-dfd298b9ca1c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4.38 s ± 14.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" | |
] | |
} | |
], | |
"source": [ | |
"%timeit eulers_scipy()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "c75131e3-2ce7-4c1a-b8b5-3f2ffdc80542", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"381 ms ± 8.94 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" | |
] | |
} | |
], | |
"source": [ | |
"%timeit eulers_eulerangles()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.9.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment