Skip to content

Commit

Permalink
Array API compatibility of norm_axis_angle
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderFabisch committed Aug 23, 2023
1 parent aa862c9 commit 2c521c9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pytransform3d/rotations/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ def norm_axis_angle(a):
of the axis vector is 1 and the angle is in [0, pi). No rotation
is represented by [1, 0, 0, 0].
"""
xp = array_namespace(a)

angle = a[3]
norm = np.linalg.norm(a[:3])
norm = xp.linalg.norm(a[:3])
if angle == 0.0 or norm == 0.0:
return np.array([1.0, 0.0, 0.0, 0.0])
res = xp.zeros_like(a)
res[0] = 1.0
return res

res = np.empty(4)
res = xp.empty_like(a)
res[:3] = a[:3] / norm

angle = norm_angle(angle)
Expand Down

0 comments on commit 2c521c9

Please sign in to comment.