Skip to content

Commit ffa468c

Browse files
committed
Removed recompile from fastmath
1 parent 4a5b0cf commit ffa468c

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

stumpy/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def _save():
218218
None
219219
"""
220220
_enable()
221+
_clear()
221222
_recompile()
222223

223224
return

stumpy/fastmath.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
import warnings
23

34
import numba
45
from numba import njit
@@ -55,11 +56,13 @@ def _set(module_name, func_name, flag):
5556
func = getattr(module, func_name)
5657
try:
5758
func.targetoptions["fastmath"] = flag
58-
func.recompile()
59+
msg = "One or more fastmath flags have been set/reset. "
60+
msg += "Please call `cache._recompile()` to ensure that all njit functions "
61+
msg += "are properly recompiled."
62+
warnings.warn(msg)
5963
except AttributeError as e:
6064
if numba.config.DISABLE_JIT and (
6165
str(e) == "'function' object has no attribute 'targetoptions'"
62-
or str(e) == "'function' object has no attribute 'recompile'"
6366
):
6467
pass
6568
else: # pragma: no cover

tests/test_fastmath.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numba
22
import numpy as np
33

4-
from stumpy import fastmath
4+
from stumpy import cache, fastmath
55

66

77
def test_set():
@@ -11,11 +11,13 @@ def test_set():
1111

1212
# case1: flag=False
1313
fastmath._set("fastmath", "_add_assoc", flag=False)
14+
cache._recompile()
1415
out = fastmath._add_assoc(0, np.inf)
1516
assert np.isnan(out)
1617

1718
# case2: flag={'reassoc', 'nsz'}
1819
fastmath._set("fastmath", "_add_assoc", flag={"reassoc", "nsz"})
20+
cache._recompile()
1921
out = fastmath._add_assoc(0, np.inf)
2022
if numba.config.DISABLE_JIT:
2123
assert np.isnan(out)
@@ -24,11 +26,13 @@ def test_set():
2426

2527
# case3: flag={'reassoc'}
2628
fastmath._set("fastmath", "_add_assoc", flag={"reassoc"})
29+
cache._recompile()
2730
out = fastmath._add_assoc(0, np.inf)
2831
assert np.isnan(out)
2932

3033
# case4: flag={'nsz'}
3134
fastmath._set("fastmath", "_add_assoc", flag={"nsz"})
35+
cache._recompile()
3236
out = fastmath._add_assoc(0, np.inf)
3337
assert np.isnan(out)
3438

@@ -39,7 +43,9 @@ def test_reset():
3943
# https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath
4044
# and then reset it to the default value, i.e. `True`
4145
fastmath._set("fastmath", "_add_assoc", False)
46+
cache._recompile()
4247
fastmath._reset("fastmath", "_add_assoc")
48+
cache._recompile()
4349
if numba.config.DISABLE_JIT:
4450
assert np.isnan(fastmath._add_assoc(0.0, np.inf))
4551
else: # pragma: no cover

0 commit comments

Comments
 (0)