ax2qu conversion function throws if the arrays are multidimensional and last axis size is 1, even though they are broadcastable.
I appreciate having a redundant axis in an array is not ideal, but sometimes it is easier to work with it to keep the input and output shapes consistent 😄.
>>> from orix.quaternion import Quaternion
>>> import numpy as np
>>> axes = np.random.randn(2, 1, 3)
>>> angles = np.random.randn(*axes.shape[:-1])
>>> Quaternion.from_axes_angles(axes, angles)
ValueError: The dimensions of axes (2, 1) and angles (2,) are incompatible. The dimensions must match or one must be a singular value.
Description of the change
ax2qu
conversion function throws if the arrays are multidimensional and last axis size is 1, even though they are broadcastable.I appreciate having a redundant axis in an array is not ideal, but sometimes it is easier to work with it to keep the input and output shapes consistent 😄.
I have looked into the code and there appears to be a lot of shape juggling because the internal functions are numba jitted and ultimately require 2d arrays. These lines in particluar seem to be the issue: https://github.com/pyxem/orix/blob/856491e341efc695da7b483fd108491a425f884f/orix/quaternion/_conversions.py#L557-L561
I believe we should also check here if
axes.shape[:-1] == angles.shape
and this will fix the issue.Progress of the PR
Minimal example of the bug fix or new feature
With the fix in this PR:
For reviewers
__init__.py
.CHANGELOG.rst
.__credits__
inorix/__init__.py
and in.zenodo.json
.