Skip to content

Commit 92a2b41

Browse files
committed
Added coverage testing for fastmath.py
1 parent db1958a commit 92a2b41

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

stumpy/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"STUMPY_EXCL_ZONE_DENOM": 4,
2020
"STUMPY_FASTMATH_TRUE": True,
2121
"STUMPY_FASTMATH_FLAGS": {"nsz", "arcp", "contract", "afn", "reassoc"},
22+
"STUMPY_FASTMATH_FASTMATH._ADD_ASSOC": True,
2223
}
2324

2425
# In addition to these configuration variables, there exist config variables

stumpy/fastmath.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22

3+
import numba
34
from numba import njit
45

56
from . import config
@@ -52,8 +53,17 @@ def _set(module_name, func_name, flag):
5253
"""
5354
module = importlib.import_module(f".{module_name}", package="stumpy")
5455
func = getattr(module, func_name)
55-
func.targetoptions["fastmath"] = flag
56-
func.recompile()
56+
try:
57+
func.targetoptions["fastmath"] = flag
58+
func.recompile()
59+
except AttributeError as e:
60+
if numba.config.DISABLE_JIT and (
61+
str(e) == "'function' object has no attribute 'targetoptions'"
62+
or str(e) == "'function' object has no attribute 'recompile'"
63+
):
64+
pass
65+
else: # pragma: no cover
66+
raise
5767

5868
return
5969

test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ set_ray_coveragerc()
170170
show_coverage_report()
171171
{
172172
set_ray_coveragerc
173-
coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,tests/test_fastmath.py $fcoveragerc
173+
coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py $fcoveragerc
174174
}
175175

176176
gen_coverage_xml_report()
177177
{
178178
# This function saves the coverage report in Cobertura XML format, which is compatible with codecov
179179
set_ray_coveragerc
180-
coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,tests/test_fastmath.py $fcoveragerc
180+
coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py $fcoveragerc
181181
}
182182

183183
test_custom()

tests/test_fastmath.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import numba
22
import numpy as np
3-
import pytest
43

54
from stumpy import fastmath
65

7-
if numba.config.DISABLE_JIT:
8-
pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True)
9-
106

117
def test_set():
128
# The test is done by changing the value of fastmath flag for
@@ -21,7 +17,10 @@ def test_set():
2117
# case2: flag={'reassoc', 'nsz'}
2218
fastmath._set("fastmath", "_add_assoc", flag={"reassoc", "nsz"})
2319
out = fastmath._add_assoc(0, np.inf)
24-
assert out == 0.0
20+
if numba.config.DISABLE_JIT:
21+
assert np.isnan(out)
22+
else: # pragma: no cover
23+
assert out == 0.0
2524

2625
# case3: flag={'reassoc'}
2726
fastmath._set("fastmath", "_add_assoc", flag={"reassoc"})
@@ -41,4 +40,7 @@ def test_reset():
4140
# and then reset it to the default value, i.e. `True`
4241
fastmath._set("fastmath", "_add_assoc", False)
4342
fastmath._reset("fastmath", "_add_assoc")
44-
assert fastmath._add_assoc(0.0, np.inf) == 0.0
43+
if numba.config.DISABLE_JIT:
44+
assert np.isnan(fastmath._add_assoc(0.0, np.inf))
45+
else: # pragma: no cover
46+
assert fastmath._add_assoc(0.0, np.inf) == 0.0

0 commit comments

Comments
 (0)