pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

:rocket: Increase performance of axis-angle conversions

Open Theo-Cheynel opened this issue 1 year ago • 3 comments

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)

Theo-Cheynel avatar May 24 '23 14:05 Theo-Cheynel

@bottler has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Jul 14 '23 14:07 facebook-github-bot

I'm worried about very small angles here. The current implementations delegate to other functions which are being really careful about nasty angles.

bottler avatar Jul 14 '23 15:07 bottler

@Theo-Cheynel has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Jul 26 '23 16:07 facebook-github-bot