import importlib
import numba
import numpy as np
import pytest
from stumpy import _get_fastmath_value, cache, fastmath
def test_set():
fastmath._set("fastmath", "_add_assoc", flag=False)
cache._recompile()
out = fastmath._add_assoc(0, np.inf)
assert np.isnan(out)
fastmath._set("fastmath", "_add_assoc", flag={"reassoc", "nsz"})
cache._recompile()
out = fastmath._add_assoc(0, np.inf)
if numba.config.DISABLE_JIT:
assert np.isnan(out)
else:
assert out == 0.0
fastmath._set("fastmath", "_add_assoc", flag={"reassoc"})
cache._recompile()
out = fastmath._add_assoc(0, np.inf)
assert np.isnan(out)
fastmath._set("fastmath", "_add_assoc", flag={"nsz"})
cache._recompile()
out = fastmath._add_assoc(0, np.inf)
assert np.isnan(out)
def test_reset():
fastmath._set("fastmath", "_add_assoc", False)
cache._recompile()
fastmath._reset("fastmath", "_add_assoc")
cache._recompile()
if numba.config.DISABLE_JIT:
assert np.isnan(fastmath._add_assoc(0.0, np.inf))
else:
assert fastmath._add_assoc(0.0, np.inf) == 0.0
@pytest.mark.skipif(numba.config.DISABLE_JIT, reason="JIT Disabled")
def test_get_fastmath_value():
njit_funcs = cache.get_njit_funcs()
for module_name, func_name in njit_funcs:
module = importlib.import_module(f".{module_name}", package="stumpy")
func = getattr(module, func_name)
ref = func.targetoptions["fastmath"]
cmp = _get_fastmath_value(module_name, func_name)
assert ref == cmp