Skip to content

Commit 5009ad5

Browse files
committed
ENH: Set w2_thresh to positive values for clarity, update doc to indicate 3*eps
1 parent fb2c8e8 commit 5009ad5

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ class Nifti1Header(SpmAnalyzeHeader):
688688
single_magic = b'n+1'
689689

690690
# Quaternion threshold near 0, based on float32 precision
691-
quaternion_threshold = -np.finfo(np.float32).eps * 3
691+
quaternion_threshold = np.finfo(np.float32).eps * 3
692692

693693
def __init__(self, binaryblock=None, endianness=None, check=True, extensions=()):
694694
"""Initialize header from binary data block and extensions"""

nibabel/quaternions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def fillpositive(xyz, w2_thresh=None):
4444
w2_thresh : None or float, optional
4545
threshold to determine if w squared is non-zero.
4646
If None (default) then w2_thresh set equal to
47-
``-np.finfo(xyz.dtype).eps``, if possible, otherwise
48-
``-np.finfo(np.float64).eps``
47+
3 * ``np.finfo(xyz.dtype).eps``, if possible, otherwise
48+
3 * ``np.finfo(np.float64).eps``
4949
5050
Returns
5151
-------
@@ -89,9 +89,9 @@ def fillpositive(xyz, w2_thresh=None):
8989
# If necessary, guess precision of input
9090
if w2_thresh is None:
9191
try: # trap errors for non-array, integer array
92-
w2_thresh = -np.finfo(xyz.dtype).eps * 3
92+
w2_thresh = np.finfo(xyz.dtype).eps * 3
9393
except (AttributeError, ValueError):
94-
w2_thresh = -FLOAT_EPS * 3
94+
w2_thresh = FLOAT_EPS * 3
9595
# Use maximum precision
9696
xyz = np.asarray(xyz, dtype=MAX_FLOAT)
9797
# Calculate w

nibabel/tests/test_quaternions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_fillpos_precision(dtype):
7474
# Check that a random unit vector will be extended with 0
7575
rand = np.random.default_rng()
7676
# Permit 1 epsilon per value
77-
w2_thresh = 3 * -np.finfo(dtype).eps
77+
w2_thresh = 3 * np.finfo(dtype).eps
7878

7979
pos_error = neg_error = False
8080
for _ in range(50):

0 commit comments

Comments
 (0)