Skip to content

Commit 943c13d

Browse files
committed
ENH: Set symmetric threshold for identifying unit quaternions in qform calculation
1 parent 41ce88c commit 943c13d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

nibabel/quaternions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def fillpositive(xyz, w2_thresh=None):
4242
xyz : iterable
4343
iterable containing 3 values, corresponding to quaternion x, y, z
4444
w2_thresh : None or float, optional
45-
threshold to determine if w squared is really negative.
45+
threshold to determine if w squared is non-zero.
4646
If None (default) then w2_thresh set equal to
4747
``-np.finfo(xyz.dtype).eps``, if possible, otherwise
4848
``-np.finfo(np.float64).eps``
@@ -95,11 +95,11 @@ def fillpositive(xyz, w2_thresh=None):
9595
# Use maximum precision
9696
xyz = np.asarray(xyz, dtype=MAX_FLOAT)
9797
# Calculate w
98-
w2 = 1.0 - np.dot(xyz, xyz)
99-
if w2 < 0:
100-
if w2 < w2_thresh:
101-
raise ValueError(f'w2 should be positive, but is {w2:e}')
98+
w2 = 1.0 - xyz @ xyz
99+
if np.abs(w2) < np.abs(w2_thresh):
102100
w = 0
101+
elif w2 < 0:
102+
raise ValueError(f'w2 should be positive, but is {w2:e}')
103103
else:
104104
w = np.sqrt(w2)
105105
return np.r_[w, xyz]

0 commit comments

Comments
 (0)