Skip to content

Commit

Permalink
Make norm array api compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderFabisch committed Aug 22, 2023
1 parent 559e4dd commit 84c273d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pytransform3d/rotations/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utility functions for rotations."""
import warnings
import math
import array_api_compat
import numpy as np
from ._constants import unitz, eps, two_pi

Expand All @@ -18,11 +19,13 @@ def norm_vector(v):
u : array, shape (n,)
nd unit vector with norm 1 or the zero vector
"""
norm = np.linalg.norm(v)
xp = array_api_compat.array_namespace(v)

norm = xp.linalg.norm(v)
if norm == 0.0:
return v

return np.asarray(v) / norm
return xp.asarray(v) / norm


def norm_matrix(R):
Expand Down

0 comments on commit 84c273d

Please sign in to comment.