Skip to content

Commit 9a69593

Browse files
committed
improve readability
1 parent b82b3c9 commit 9a69593

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tests/test_fastmath.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numba
22
import numpy as np
33
import pytest
4-
from numba import njit
54

65
from stumpy import fastmath
76

@@ -10,32 +9,36 @@
109

1110

1211
def test_set():
13-
# Test the _set and _reset function in fastmath.py
1412
# The test is done by changing the value of fastmath flag for
1513
# the fastmath._add_assoc function, taken from the following link:
1614
# https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
17-
py_func = fastmath._add_assoc.py_func
1815

19-
x = 0.0
20-
y = np.inf
21-
fastmath_flags = [False, {"reassoc", "nsz"}, {"reassoc"}, {"nsz"}]
22-
for flag in fastmath_flags:
23-
ref = njit(fastmath=flag)(py_func)(x, y)
16+
# case1: flag=False
17+
fastmath._set("fastmath", "_add_assoc", flag=False)
18+
out = fastmath._add_assoc(0, np.inf)
19+
assert np.isnan(out)
2420

25-
fastmath._set("fastmath", "_add_assoc", flag)
26-
comp = fastmath._add_assoc(x, y)
21+
# case2: flag={'reassoc', 'nsz'}
22+
fastmath._set("fastmath", "_add_assoc", flag={"reassoc", "nsz"})
23+
out = fastmath._add_assoc(0, np.inf)
24+
assert out == 0.0
2725

28-
if np.isnan(ref) and np.isnan(comp):
29-
assert True
30-
else:
31-
assert ref == comp
26+
# case3: flag={'reassoc'}
27+
fastmath._set("fastmath", "_add_assoc", flag={"reassoc"})
28+
out = fastmath._add_assoc(0, np.inf)
29+
assert np.isnan(out)
30+
31+
# case4: flag={'nsz'}
32+
fastmath._set("fastmath", "_add_assoc", flag={"nsz"})
33+
out = fastmath._add_assoc(0, np.inf)
34+
assert np.isnan(out)
3235

3336

3437
def test_reset():
35-
# Test the _set and _reset function in fastmath.py
3638
# The test is done by changing the value of fastmath flag for
3739
# the fastmath._add_assoc function, taken from the following link:
3840
# https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
41+
# and then reset it to the default value, i.e. `True`
3942
fastmath._set("fastmath", "_add_assoc", False)
4043
fastmath._reset("fastmath", "_add_assoc")
4144
assert fastmath._add_assoc(0.0, np.inf) == 0.0

0 commit comments

Comments
 (0)