Skip to content

Commit

Permalink
Use copies of arrays to compare quaternions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Nov 9, 2021
1 parent ad62a59 commit af7a2bb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ahrs/utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def qdist(q1: np.ndarray, q2: np.ndarray) -> float:
Euclidean distance between given unit quaternions
"""
_quaternions_guard_clauses(q1, q2)
q1, q2 = np.copy(q1), np.copy(q2)
if q1.ndim == 1:
q1 /= np.linalg.norm(q1)
q2 /= np.linalg.norm(q2)
Expand Down Expand Up @@ -293,6 +294,7 @@ def qeip(q1: np.ndarray, q2: np.ndarray) -> float:
Euclidean distance of inner products between given unit quaternions.
"""
_quaternions_guard_clauses(q1, q2)
q1, q2 = np.copy(q1), np.copy(q2)
if q1.ndim == 1:
q1 /= np.linalg.norm(q1)
q2 /= np.linalg.norm(q2)
Expand Down Expand Up @@ -325,6 +327,7 @@ def qcip(q1: np.ndarray, q2: np.ndarray) -> float:
Cosine of inner products of quaternions.
"""
_quaternions_guard_clauses(q1, q2)
q1, q2 = np.copy(q1), np.copy(q2)
if q1.ndim == 1:
q1 /= np.linalg.norm(q1)
q2 /= np.linalg.norm(q2)
Expand Down Expand Up @@ -354,6 +357,7 @@ def qad(q1: np.ndarray, q2: np.ndarray) -> float:
Angle difference between given unit quaternions.
"""
_quaternions_guard_clauses(q1, q2)
q1, q2 = np.copy(q1), np.copy(q2)
if q1.ndim == 1:
q1 /= np.linalg.norm(q1)
q2 /= np.linalg.norm(q2)
Expand Down

0 comments on commit af7a2bb

Please sign in to comment.