Skip to content

Commit ecaead2

Browse files
committed
Revised test functions
1 parent 02115b2 commit ecaead2

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

tests/test_fastmath.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
import numpy as np
2+
from numba import njit
23

34
from stumpy import fastmath
45

56

6-
def test_fastmath():
7+
def test_set():
78
# Test the _set and _reset function in fastmath.py
89
# The test is done by changing the value of fastmath flag for
9-
# the fastmath._add_assoc function
10-
# See: https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
10+
# the fastmath._add_assoc function, taken from the following link:
11+
# https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
12+
py_func = fastmath._add_assoc.py_func
1113

12-
x, y = 0.0, np.inf
14+
x = 0.0
15+
y = np.inf
16+
fastmath_flags = [False, {"reassoc", "nsz"}, {"reassoc"}, {"nsz"}]
17+
for flag in fastmath_flags:
18+
ref = njit(fastmath=flag)(py_func)(x, y)
1319

14-
# fastmath=False
15-
fastmath._set("fastmath", "_add_assoc", False)
16-
out = fastmath._add_assoc(x, y)
17-
assert np.isnan(out)
18-
19-
# fastmath={'reassoc', 'nsz'}
20-
fastmath._set("fastmath", "_add_assoc", {"reassoc", "nsz"})
21-
out = fastmath._add_assoc(x, y)
22-
assert out == 0.0
20+
fastmath._set("fastmath", "_add_assoc", flag)
21+
comp = fastmath._add_assoc(x, y)
2322

24-
# fastmath={'reassoc'}
25-
fastmath._set("fastmath", "_add_assoc", {"reassoc"})
26-
out = fastmath._add_assoc(x, y)
27-
assert np.isnan(out)
23+
if np.isnan(ref) and np.isnan(comp):
24+
assert True
25+
else:
26+
assert ref == comp
2827

29-
# fastmath={'nsz'}
30-
fastmath._set("fastmath", "_add_assoc", {"nsz"})
31-
out = fastmath._add_assoc(x, y)
32-
assert np.isnan(out)
3328

34-
# reset value of fastmath (default is True)
29+
def test_reset():
30+
# Test the _set and _reset function in fastmath.py
31+
# The test is done by changing the value of fastmath flag for
32+
# the fastmath._add_assoc function, taken from the following link:
33+
# https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
34+
fastmath._set("fastmath", "_add_assoc", False)
3535
fastmath._reset("fastmath", "_add_assoc")
36-
out = fastmath._add_assoc(x, y)
37-
assert out == 0.0
36+
assert fastmath._add_assoc(0.0, np.inf) == 0.0

0 commit comments

Comments
 (0)