pytorch3d
pytorch3d copied to clipboard
:rocket: Increase performance of axis-angle conversions
Motivations and context
When converting from axis-angle to matrix and back, current rotation_conversions.py does an intermediate step by converting to quaternions. There exists a faster way using Rodrigues' rotation formula .
Changes
Used the formulas for both axis-angle to matrix and matrix to axis-angle conversions. The changes work with any number of batch dimensions, just like the original functions.
Effect
There is a 2x speedup when converting from axis-angle to matrix, and this speedup is consistent regardless of device and batch size. There is a 5-8x speedup when converting from matrix to axis-angle.
The only difference in the results happens in matrix_to_axis_angle, when you give as input a matrix that is not a rotation matrix. This behaviour is undocumented anyway and the results do not make sense either way. If this is really an issue, we can always merge only the first part of the changes, or we could check that the matrix is orthogonal and run the previous code if it isn't (for backwards compatibility)
@bottler has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
I'm worried about very small angles here. The current implementations delegate to other functions which are being really careful about nasty angles.
@Theo-Cheynel has updated the pull request. You must reimport the pull request before landing.