From 0d4abf07e3a7bb75b4c383b87d1477099eadf085 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 5 Dec 2024 12:29:25 -0500 Subject: [PATCH 01/68] removed reassoc flag from fastmath --- stumpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/core.py b/stumpy/core.py index 4cdaea02a..8c09d4ab7 100644 --- a/stumpy/core.py +++ b/stumpy/core.py @@ -1042,7 +1042,7 @@ def compute_mean_std(T, m): @njit( # "f8(i8, f8, f8, f8, f8, f8)", - fastmath={"nsz", "arcp", "contract", "afn", "reassoc"} + fastmath={"nsz", "arcp", "contract", "afn"} ) def _calculate_squared_distance( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant From 7b9a2a3020207b305f223e63893b441887e58bf1 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 03:58:19 -0500 Subject: [PATCH 02/68] Add reset feature to config --- stumpy/config.py | 81 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 10 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index dad017ec3..212e1137c 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -3,14 +3,75 @@ # STUMPY is a trademark of TD Ameritrade IP Company, Inc. All rights reserved. import numpy as np +import warnings -STUMPY_THREADS_PER_BLOCK = 512 -STUMPY_MEAN_STD_NUM_CHUNKS = 1 -STUMPY_MEAN_STD_MAX_ITER = 10 -STUMPY_DENOM_THRESHOLD = 1e-14 -STUMPY_STDDEV_THRESHOLD = 1e-7 -STUMPY_P_NORM_THRESHOLD = 1e-14 -STUMPY_TEST_PRECISION = 5 -STUMPY_MAX_P_NORM_DISTANCE = np.finfo(np.float64).max -STUMPY_MAX_DISTANCE = np.sqrt(STUMPY_MAX_P_NORM_DISTANCE) -STUMPY_EXCL_ZONE_DENOM = 4 +_STUMPY_DEFAULTS = { + "STUMPY_THREADS_PER_BLOCK": 512, + "STUMPY_MEAN_STD_NUM_CHUNKS": 1, + "STUMPY_MEAN_STD_MAX_ITER": 10, + "STUMPY_DENOM_THRESHOLD": 1e-14, + "STUMPY_STDDEV_THRESHOLD": 1e-7, + "STUMPY_P_NORM_THRESHOLD": 1e-14, + "STUMPY_TEST_PRECISION": 5, + "STUMPY_MAX_P_NORM_DISTANCE": np.finfo(np.float64).max, + "STUMPY_MAX_DISTANCE": np.sqrt(np.finfo(np.float64).max), + "STUMPY_EXCL_ZONE_DENOM": 4, + "STUMPY_FASTMATH": True, + "STUMPY_FASTMATH_FLAGS": {"nnan", "ninf", "nsz", "arcp", "contract", "afn", "reassoc"}, +} + +STUMPY_THREADS_PER_BLOCK = _STUMPY_DEFAULTS["STUMPY_THREADS_PER_BLOCK"] +STUMPY_MEAN_STD_NUM_CHUNKS = _STUMPY_DEFAULTS["STUMPY_MEAN_STD_NUM_CHUNKS"] +STUMPY_MEAN_STD_MAX_ITER = _STUMPY_DEFAULTS["STUMPY_MEAN_STD_MAX_ITER"] +STUMPY_DENOM_THRESHOLD = _STUMPY_DEFAULTS["STUMPY_DENOM_THRESHOLD"] +STUMPY_STDDEV_THRESHOLD = _STUMPY_DEFAULTS["STUMPY_STDDEV_THRESHOLD"] +STUMPY_P_NORM_THRESHOLD = _STUMPY_DEFAULTS["STUMPY_P_NORM_THRESHOLD"] +STUMPY_TEST_PRECISION = _STUMPY_DEFAULTS["STUMPY_TEST_PRECISION"] +STUMPY_MAX_P_NORM_DISTANCE = _STUMPY_DEFAULTS["STUMPY_MAX_P_NORM_DISTANCE"] +STUMPY_MAX_DISTANCE = _STUMPY_DEFAULTS["STUMPY_MAX_DISTANCE"] +STUMPY_EXCL_ZONE_DENOM = _STUMPY_DEFAULTS["STUMPY_EXCL_ZONE_DENOM"] +STUMPY_FASTMATH = _STUMPY_DEFAULTS["STUMPY_FASTMATH"] +STUMPY_FASTMATH_FLAGS = _STUMPY_DEFAULTS["STUMPY_FASTMATH_FLAGS"] + + +def _reset(var=None): + """ + Reset the value of a configuration variable(s) to their default value(s) + + Parameters + ---------- + var : str or list, default None + If str, it is the name of the configuration variable to reset. If lst, + it is a list of configuration variables to reset. If None, then all + configuration variables are reset to their default values. + + Raises + ------ + UserWarning + If the specified configuration variable is not recognized + """ + config_vars = [ + k + for k, _ in globals().items() + if k.isupper() and k.startswith("STUMPY") + ] + + if var is None: + var = config_vars + elif isinstance(var, str): + var = [var] + else: + pass + + if not set(var).issubset(config_vars): + msg = ( + f"Could not reset the following unrecognized configuration variable(s): " + + f"{set(var) - set(config_vars)}" + ) + warnings.warn(msg) + + # Reset all config variables back to default values + for v in var: + globals()[v] = _STUMPY_DEFAULTS[v] + + return \ No newline at end of file From 95e7d8f200007449a4d9daa565578bc0f339d0ad Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 04:01:03 -0500 Subject: [PATCH 03/68] Revised config value --- stumpy/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/config.py b/stumpy/config.py index 212e1137c..309556228 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -17,7 +17,7 @@ "STUMPY_MAX_DISTANCE": np.sqrt(np.finfo(np.float64).max), "STUMPY_EXCL_ZONE_DENOM": 4, "STUMPY_FASTMATH": True, - "STUMPY_FASTMATH_FLAGS": {"nnan", "ninf", "nsz", "arcp", "contract", "afn", "reassoc"}, + "STUMPY_FASTMATH_FLAGS": {"nsz", "arcp", "contract", "afn", "reassoc"}, } STUMPY_THREADS_PER_BLOCK = _STUMPY_DEFAULTS["STUMPY_THREADS_PER_BLOCK"] From 1f95f775447e2dbd9f8aa4821f3b2048672e6175 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 04:04:28 -0500 Subject: [PATCH 04/68] replaced fastmath flags with config var --- stumpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/core.py b/stumpy/core.py index 8c09d4ab7..b748187b9 100644 --- a/stumpy/core.py +++ b/stumpy/core.py @@ -1042,7 +1042,7 @@ def compute_mean_std(T, m): @njit( # "f8(i8, f8, f8, f8, f8, f8)", - fastmath={"nsz", "arcp", "contract", "afn"} + fastmath=config.STUMPY_FASTMATH_FLAGS ) def _calculate_squared_distance( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant From 37add8455a9c76cf0ef492c1924bf04371a50503 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 04:08:43 -0500 Subject: [PATCH 05/68] fixed format --- stumpy/config.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index 309556228..16efe2e2a 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -44,16 +44,14 @@ def _reset(var=None): If str, it is the name of the configuration variable to reset. If lst, it is a list of configuration variables to reset. If None, then all configuration variables are reset to their default values. - + Raises ------ UserWarning If the specified configuration variable is not recognized """ config_vars = [ - k - for k, _ in globals().items() - if k.isupper() and k.startswith("STUMPY") + k for k, _ in globals().items() if k.isupper() and k.startswith("STUMPY") ] if var is None: @@ -65,13 +63,13 @@ def _reset(var=None): if not set(var).issubset(config_vars): msg = ( - f"Could not reset the following unrecognized configuration variable(s): " + f"Could not reset the following unrecognized configuration variable(s): " + f"{set(var) - set(config_vars)}" ) warnings.warn(msg) - + # Reset all config variables back to default values for v in var: globals()[v] = _STUMPY_DEFAULTS[v] - return \ No newline at end of file + return From c795b9dcb5d00239feacea47171486ab0da8a1db Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 04:36:50 -0500 Subject: [PATCH 06/68] Removed bad f-string --- stumpy/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index 16efe2e2a..481a718fa 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -2,9 +2,10 @@ # Copyright 2019 TD Ameritrade. Released under the terms of the 3-Clause BSD license. # STUMPY is a trademark of TD Ameritrade IP Company, Inc. All rights reserved. -import numpy as np import warnings +import numpy as np + _STUMPY_DEFAULTS = { "STUMPY_THREADS_PER_BLOCK": 512, "STUMPY_MEAN_STD_NUM_CHUNKS": 1, @@ -63,7 +64,7 @@ def _reset(var=None): if not set(var).issubset(config_vars): msg = ( - f"Could not reset the following unrecognized configuration variable(s): " + "Could not reset the following unrecognized configuration variable(s): " + f"{set(var) - set(config_vars)}" ) warnings.warn(msg) From 27743026cf320497b1e89fcc9f65244f7492362b Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 04:38:32 -0500 Subject: [PATCH 07/68] Replaced Raised with Returns in docstring --- stumpy/config.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index 481a718fa..80d7146d7 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -46,10 +46,9 @@ def _reset(var=None): it is a list of configuration variables to reset. If None, then all configuration variables are reset to their default values. - Raises + Returns ------ - UserWarning - If the specified configuration variable is not recognized + None """ config_vars = [ k for k, _ in globals().items() if k.isupper() and k.startswith("STUMPY") From 80544c7c1353ba8750f483f8f3d19932af68508f Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 05:42:09 -0500 Subject: [PATCH 08/68] Add second attempt for assertion --- tests/test_precision.py | 77 ++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index c87985092..87580ca1a 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -1,4 +1,5 @@ import functools +import importlib from unittest.mock import patch import naive @@ -8,7 +9,7 @@ from numba import cuda import stumpy -from stumpy import config, core +from stumpy import cache, config, core try: from numba.errors import NumbaPerformanceWarning @@ -146,20 +147,70 @@ def test_snippets(): cmp_regimes, ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) - npt.assert_almost_equal( - ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION + # Revise fastmath flag, recompile, and re-calculate snippets, + # and then revert the changes + config.STUMPY_FASTMATH_FLAGS = {"nsz", "arcp", "contract", "afn"} + core._calculate_squared_distance.targetoptions["fastmath"] = ( + config.STUMPY_FASTMATH_FLAGS ) - npt.assert_almost_equal( - ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION + 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) + func.recompile() + + ( + cmp_snippets_NOreassoc, + cmp_indices_NOreassoc, + cmp_profiles_NOreassoc, + cmp_fractions_NOreassoc, + cmp_areas_NOreassoc, + cmp_regimes_NOreassoc, + ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) + + config._reset("STUMPY_FASTMATH_FLAGS") + core._calculate_squared_distance.targetoptions["fastmath"] = ( + config.STUMPY_FASTMATH_FLAGS ) - npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION) - npt.assert_almost_equal(ref_regimes, cmp_regimes) + for module_name, func_name in njit_funcs: + module = importlib.import_module(f".{module_name}", package="stumpy") + func = getattr(module, func_name) + func.recompile() + + if np.allclose(ref_snippets, cmp_snippets): + npt.assert_almost_equal( + ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal(ref_regimes, cmp_regimes) + else: + npt.assert_almost_equal( + ref_snippets, cmp_snippets_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_indices, cmp_indices_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_profiles, cmp_profiles_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_fractions, cmp_fractions_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_areas, cmp_areas_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal(ref_regimes, cmp_regimes_NOreassoc) @pytest.mark.filterwarnings("ignore", category=NumbaPerformanceWarning) From a080495376eaad0bed2010e1f11c90741ce5bc6d Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 06:16:56 -0500 Subject: [PATCH 09/68] minor change --- stumpy/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/config.py b/stumpy/config.py index 80d7146d7..bcec1e679 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -47,7 +47,7 @@ def _reset(var=None): configuration variables are reset to their default values. Returns - ------ + ------- None """ config_vars = [ From 976ec136af2e31db230451b502ef200fed90d7ed Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 22 Dec 2024 16:07:49 -0500 Subject: [PATCH 10/68] Add condition to avoid revising fastmath when JIT is disabled --- tests/test_precision.py | 69 +++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index 87580ca1a..ad298594d 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -3,6 +3,7 @@ from unittest.mock import patch import naive +import numba import numpy as np import numpy.testing as npt import pytest @@ -138,6 +139,7 @@ def test_snippets(): ) = naive.mpdist_snippets( T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func ) + ( cmp_snippets, cmp_indices, @@ -147,37 +149,7 @@ def test_snippets(): cmp_regimes, ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) - # Revise fastmath flag, recompile, and re-calculate snippets, - # and then revert the changes - config.STUMPY_FASTMATH_FLAGS = {"nsz", "arcp", "contract", "afn"} - core._calculate_squared_distance.targetoptions["fastmath"] = ( - config.STUMPY_FASTMATH_FLAGS - ) - 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) - func.recompile() - - ( - cmp_snippets_NOreassoc, - cmp_indices_NOreassoc, - cmp_profiles_NOreassoc, - cmp_fractions_NOreassoc, - cmp_areas_NOreassoc, - cmp_regimes_NOreassoc, - ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) - - config._reset("STUMPY_FASTMATH_FLAGS") - core._calculate_squared_distance.targetoptions["fastmath"] = ( - config.STUMPY_FASTMATH_FLAGS - ) - for module_name, func_name in njit_funcs: - module = importlib.import_module(f".{module_name}", package="stumpy") - func = getattr(module, func_name) - func.recompile() - - if np.allclose(ref_snippets, cmp_snippets): + if np.allclose(ref_snippets, cmp_snippets) or numba.config.DISABLE_JIT: npt.assert_almost_equal( ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION ) @@ -195,6 +167,41 @@ def test_snippets(): ) npt.assert_almost_equal(ref_regimes, cmp_regimes) else: + # Revise fastmath flag, recompile, and re-calculate snippets, + # and then revert the changes + + config.STUMPY_FASTMATH_FLAGS = {"nsz", "arcp", "contract", "afn"} + core._calculate_squared_distance.targetoptions["fastmath"] = ( + config.STUMPY_FASTMATH_FLAGS + ) + + 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) + func.recompile() + + ( + cmp_snippets_NOreassoc, + cmp_indices_NOreassoc, + cmp_profiles_NOreassoc, + cmp_fractions_NOreassoc, + cmp_areas_NOreassoc, + cmp_regimes_NOreassoc, + ) = stumpy.snippets( + T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func + ) + + config._reset("STUMPY_FASTMATH_FLAGS") + + core._calculate_squared_distance.targetoptions["fastmath"] = ( + config.STUMPY_FASTMATH_FLAGS + ) + for module_name, func_name in njit_funcs: + module = importlib.import_module(f".{module_name}", package="stumpy") + func = getattr(module, func_name) + func.recompile() + npt.assert_almost_equal( ref_snippets, cmp_snippets_NOreassoc, decimal=config.STUMPY_TEST_PRECISION ) From b24ff9d10bde57265887e0ebf6d65ffdac032acf Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Mon, 23 Dec 2024 00:07:17 -0500 Subject: [PATCH 11/68] Removed support for input with type list to simplify function --- stumpy/config.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index bcec1e679..aa50d5de2 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -41,9 +41,8 @@ def _reset(var=None): Parameters ---------- - var : str or list, default None - If str, it is the name of the configuration variable to reset. If lst, - it is a list of configuration variables to reset. If None, then all + var : str, default None + The name of the configuration variable. If None, then all configuration variables are reset to their default values. Returns @@ -55,21 +54,12 @@ def _reset(var=None): ] if var is None: - var = config_vars - elif isinstance(var, str): - var = [var] + for v in config_vars: + globals()[v] = _STUMPY_DEFAULTS[v] + elif var in config_vars: + globals()[var] = _STUMPY_DEFAULTS[var] else: - pass - - if not set(var).issubset(config_vars): - msg = ( - "Could not reset the following unrecognized configuration variable(s): " - + f"{set(var) - set(config_vars)}" - ) + msg = f'Could not reset unrecognized configuration variable "{var}"' warnings.warn(msg) - # Reset all config variables back to default values - for v in var: - globals()[v] = _STUMPY_DEFAULTS[v] - return From d13a32bc2b52bd9c4cc41d764c84781cc21f3176 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Mon, 23 Dec 2024 23:38:35 -0500 Subject: [PATCH 12/68] Refactored the recompile process --- stumpy/cache.py | 42 +++++++++++++++++++ tests/test_precision.py | 92 ++++++++++++++--------------------------- 2 files changed, 74 insertions(+), 60 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 398387724..2fd300f1d 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -9,6 +9,8 @@ import site import warnings +import numba + CACHE_WARNING = "Caching `numba` functions is purely for experimental purposes " CACHE_WARNING += "and should never be used or depended upon as it is not supported! " CACHE_WARNING += "All caching capabilities are not tested and may be removed/changed " @@ -107,3 +109,43 @@ def _get_cache(): site_pkg_dir = site.getsitepackages()[0] numba_cache_dir = site_pkg_dir + "/stumpy/__pycache__" return [f.name for f in pathlib.Path(numba_cache_dir).glob("*nb*") if f.is_file()] + + +def _recompile(func=None, fastmath=None): + """ + Recompile a jit/njit decorated function. If `func` is None, then it wiil + recompile all njit functions of STUMPY. + + Parameters + ---------- + func : a njit function, default None + The numba function to recompile. If None, then all njit functions + of STUMPY will be recompiled. + + fastmath : bool or set, default None + The fastmath flags to use. If None, then the func's fastmath flags + will not be changed. This is only used when `func` is provided. + + Returns + ------- + None + """ + warnings.warn(CACHE_WARNING) + if func is None: + njit_funcs = 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) + func.recompile() + + else: + if not numba.extending.is_jitted(func): + msg = "The function `func` must be a (n)jit function." + raise ValueError(msg) + + if fastmath is not None: + func.targetoptions["fastmath"] = fastmath + + func.recompile() + + return diff --git a/tests/test_precision.py b/tests/test_precision.py index ad298594d..784121d40 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -1,5 +1,4 @@ import functools -import importlib from unittest.mock import patch import naive @@ -149,75 +148,48 @@ def test_snippets(): cmp_regimes, ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) - if np.allclose(ref_snippets, cmp_snippets) or numba.config.DISABLE_JIT: - npt.assert_almost_equal( - ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal(ref_regimes, cmp_regimes) - else: - # Revise fastmath flag, recompile, and re-calculate snippets, - # and then revert the changes - + if not np.allclose(ref_snippets, cmp_snippets) and not numba.config.DISABLE_JIT: + # Revise fastmath flags by removing reassoc (to improve precision), + # recompile njit functions, and re-compute snippets. config.STUMPY_FASTMATH_FLAGS = {"nsz", "arcp", "contract", "afn"} - core._calculate_squared_distance.targetoptions["fastmath"] = ( - config.STUMPY_FASTMATH_FLAGS + cache._recompile( + core._calculate_squared_distance, fastmath=config.STUMPY_FASTMATH_FLAGS ) - - 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) - func.recompile() + cache._recompile() ( - cmp_snippets_NOreassoc, - cmp_indices_NOreassoc, - cmp_profiles_NOreassoc, - cmp_fractions_NOreassoc, - cmp_areas_NOreassoc, - cmp_regimes_NOreassoc, + cmp_snippets, + cmp_indices, + cmp_profiles, + cmp_fractions, + cmp_areas, + cmp_regimes, ) = stumpy.snippets( T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func ) - config._reset("STUMPY_FASTMATH_FLAGS") - - core._calculate_squared_distance.targetoptions["fastmath"] = ( - config.STUMPY_FASTMATH_FLAGS - ) - for module_name, func_name in njit_funcs: - module = importlib.import_module(f".{module_name}", package="stumpy") - func = getattr(module, func_name) - func.recompile() + npt.assert_almost_equal( + ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal( + ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION + ) + npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION) + npt.assert_almost_equal(ref_regimes, cmp_regimes) - npt.assert_almost_equal( - ref_snippets, cmp_snippets_NOreassoc, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_indices, cmp_indices_NOreassoc, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_profiles, cmp_profiles_NOreassoc, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_fractions, cmp_fractions_NOreassoc, decimal=config.STUMPY_TEST_PRECISION - ) - npt.assert_almost_equal( - ref_areas, cmp_areas_NOreassoc, decimal=config.STUMPY_TEST_PRECISION + if not numba.config.DISABLE_JIT: + # Revert fastmath flag back to their default values + config._reset("STUMPY_FASTMATH_FLAGS") + cache._recompile( + core._calculate_squared_distance, fastmath=config.STUMPY_FASTMATH_FLAGS ) - npt.assert_almost_equal(ref_regimes, cmp_regimes_NOreassoc) + cache._recompile() @pytest.mark.filterwarnings("ignore", category=NumbaPerformanceWarning) From 4256839c58ade35d9e05fdcfc11a6b13f91f6434 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Mon, 23 Dec 2024 23:43:01 -0500 Subject: [PATCH 13/68] removed blank lines --- stumpy/cache.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 2fd300f1d..94996c08d 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -137,15 +137,12 @@ def _recompile(func=None, fastmath=None): module = importlib.import_module(f".{module_name}", package="stumpy") func = getattr(module, func_name) func.recompile() - else: if not numba.extending.is_jitted(func): msg = "The function `func` must be a (n)jit function." raise ValueError(msg) - if fastmath is not None: func.targetoptions["fastmath"] = fastmath - func.recompile() return From f17f92d5d743bc6ff00b627c07ef3c79dd5a5f56 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 25 Dec 2024 20:54:25 -0500 Subject: [PATCH 14/68] fixed typo --- stumpy/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 94996c08d..8e5393cdc 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -113,7 +113,7 @@ def _get_cache(): def _recompile(func=None, fastmath=None): """ - Recompile a jit/njit decorated function. If `func` is None, then it wiil + Recompile a jit/njit decorated function. If `func` is None, then it will recompile all njit functions of STUMPY. Parameters From e543379ae901a904c99fa49955c9276c8ac0748c Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 25 Dec 2024 22:58:50 -0500 Subject: [PATCH 15/68] replaced hardcoded fastmath value with config var --- stumpy/aamp.py | 4 ++-- stumpy/core.py | 24 ++++++++++++------------ stumpy/maamp.py | 2 +- stumpy/mstump.py | 2 +- stumpy/scraamp.py | 4 ++-- stumpy/scrump.py | 4 ++-- stumpy/stump.py | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/stumpy/aamp.py b/stumpy/aamp.py index edc2da7af..02504ec0f 100644 --- a/stumpy/aamp.py +++ b/stumpy/aamp.py @@ -13,7 +13,7 @@ @njit( # "(f8[:], f8[:], i8, b1[:], b1[:], f8, i8[:], i8, i8, i8, f8[:, :, :]," # "f8[:, :], f8[:, :], i8[:, :, :], i8[:, :], i8[:, :], b1)", - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _compute_diagonal( T_A, @@ -186,7 +186,7 @@ def _compute_diagonal( @njit( # "(f8[:], f8[:], i8, b1[:], b1[:], i8[:], b1, i8)", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _aamp( T_A, diff --git a/stumpy/core.py b/stumpy/core.py index b748187b9..a2801410d 100644 --- a/stumpy/core.py +++ b/stumpy/core.py @@ -589,7 +589,7 @@ def check_window_size(m, max_size=None): raise ValueError(f"The window size must be less than or equal to {max_size}") -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH) def _sliding_dot_product(Q, T): """ A Numba JIT-compiled implementation of the sliding window dot product. @@ -657,7 +657,7 @@ def sliding_dot_product(Q, T): @njit( # "f8[:](f8[:], i8, b1[:])", - fastmath={"nsz", "arcp", "contract", "afn", "reassoc"} + fastmath=config.STUMPY_FASTMATH_FLAGS ) def _welford_nanvar(a, w, a_subseq_isfinite): """ @@ -771,7 +771,7 @@ def welford_nanstd(a, w=None): return np.sqrt(np.clip(welford_nanvar(a, w), a_min=0, a_max=None)) -@njit(parallel=True, fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(parallel=True, fastmath=config.STUMPY_FASTMATH_FLAGS) def _rolling_nanstd_1d(a, w): """ A Numba JIT-compiled and parallelized function for computing the rolling standard @@ -1110,7 +1110,7 @@ def _calculate_squared_distance( @njit( # "f8[:](i8, f8[:], f8, f8, f8[:], f8[:])", - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _calculate_squared_distance_profile( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant @@ -1176,7 +1176,7 @@ def _calculate_squared_distance_profile( @njit( # "f8[:](i8, f8[:], f8, f8, f8[:], f8[:])", - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def calculate_distance_profile( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant @@ -1229,7 +1229,7 @@ def calculate_distance_profile( return np.sqrt(D_squared) -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH) def _p_norm_distance_profile(Q, T, p=2.0): """ A Numba JIT-compiled and parallelized function for computing the p-normalized @@ -1505,7 +1505,7 @@ def mueen_calculate_distance_profile(Q, T): @njit( # "f8[:](f8[:], f8[:], f8[:], f8, f8, f8[:], f8[:])", - fastmath=True + fastmath=config.STUMPY_FASTMATH ) def _mass(Q, T, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant): """ @@ -1978,7 +1978,7 @@ def _get_QT(start, T_A, T_B, m): @njit( # ["(f8[:], i8, i8)", "(f8[:, :], i8, i8)"], - fastmath=True + fastmath=config.STUMPY_FASTMATH ) def _apply_exclusion_zone(a, idx, excl_zone, val): """ @@ -2308,7 +2308,7 @@ def array_to_temp_file(a): @njit( # "i8[:](i8[:], i8, i8, i8)", - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _count_diagonal_ndist(diags, m, n_A, n_B): """ @@ -2505,7 +2505,7 @@ def rolling_isfinite(a, w): ) -@njit(parallel=True, fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(parallel=True, fastmath=config.STUMPY_FASTMATH_FLAGS) def _rolling_isconstant(a, w): """ Compute the rolling isconstant for 1-D array. @@ -2842,7 +2842,7 @@ def _idx_to_mp( return P -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH) def _total_diagonal_ndists(tile_lower_diag, tile_upper_diag, tile_height, tile_width): """ Count the total number of distances covered by a range of diagonals @@ -3970,7 +3970,7 @@ def _mdl(disc_subseqs, disc_neighbors, S, n_bit=8): @njit( # "(i8, i8, f8[:, :], f8[:], i8, f8[:, :], i8[:, :], f8)", - fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}, + fastmath=config.STUMPY_FASTMATH_FLAGS, ) def _compute_multi_PI(d, idx, D, D_prime, range_start, P, I, p=2.0): """ diff --git a/stumpy/maamp.py b/stumpy/maamp.py index d142c8e40..35fe5fdb8 100644 --- a/stumpy/maamp.py +++ b/stumpy/maamp.py @@ -592,7 +592,7 @@ def _get_multi_p_norm(start, T, m, p=2.0): # "(i8, i8, i8, f8[:, :], f8[:, :], i8, i8, b1[:, :], b1[:, :], f8," # "f8[:, :], f8[:, :], f8[:, :])", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _compute_multi_p_norm( d, diff --git a/stumpy/mstump.py b/stumpy/mstump.py index 9b2dab7d4..44950106e 100644 --- a/stumpy/mstump.py +++ b/stumpy/mstump.py @@ -811,7 +811,7 @@ def _get_multi_QT(start, T, m): # "(i8, i8, i8, f8[:, :], f8[:, :], i8, i8, f8[:, :], f8[:, :], f8[:, :]," # "f8[:, :], f8[:, :], f8[:, :], f8[:, :])", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _compute_multi_D( d, diff --git a/stumpy/scraamp.py b/stumpy/scraamp.py index 5c62606e3..c85c7fa6d 100644 --- a/stumpy/scraamp.py +++ b/stumpy/scraamp.py @@ -83,7 +83,7 @@ def _preprocess_prescraamp(T_A, m, T_B=None, s=None): return (T_A, T_B, T_A_subseq_isfinite, T_B_subseq_isfinite, indices, s, excl_zone) -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH) def _compute_PI( T_A, T_B, @@ -286,7 +286,7 @@ def _compute_PI( # "(f8[:], f8[:], i8, b1[:], b1[:], f8, i8, i8, f8[:], f8[:]," # "i8[:], optional(i8))", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _prescraamp( T_A, diff --git a/stumpy/scrump.py b/stumpy/scrump.py index 7367a8885..601fc9d8e 100644 --- a/stumpy/scrump.py +++ b/stumpy/scrump.py @@ -133,7 +133,7 @@ def _preprocess_prescrump( ) -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH) def _compute_PI( T_A, T_B, @@ -384,7 +384,7 @@ def _compute_PI( # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], i8, i8, f8[:], f8[:]," # "i8[:], optional(i8))", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _prescrump( T_A, diff --git a/stumpy/stump.py b/stumpy/stump.py index 6c3a10721..dc435c2e4 100644 --- a/stumpy/stump.py +++ b/stumpy/stump.py @@ -15,7 +15,7 @@ # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], f8[:]," # "b1[:], b1[:], b1[:], b1[:], i8[:], i8, i8, i8, f8[:, :, :], f8[:, :]," # "f8[:, :], i8[:, :, :], i8[:, :], i8[:, :], b1)", - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _compute_diagonal( T_A, @@ -247,7 +247,7 @@ def _compute_diagonal( # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], b1[:], b1[:]," # "b1[:], b1[:], i8[:], b1, i8)", parallel=True, - fastmath=True, + fastmath=config.STUMPY_FASTMATH, ) def _stump( T_A, From 71fe3aa08f6913848bb46898e0ac9dbc72565341 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 26 Dec 2024 00:06:28 -0500 Subject: [PATCH 16/68] revised function --- stumpy/cache.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 8e5393cdc..7427839bb 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -9,8 +9,6 @@ import site import warnings -import numba - CACHE_WARNING = "Caching `numba` functions is purely for experimental purposes " CACHE_WARNING += "and should never be used or depended upon as it is not supported! " CACHE_WARNING += "All caching capabilities are not tested and may be removed/changed " @@ -131,16 +129,21 @@ def _recompile(func=None, fastmath=None): None """ warnings.warn(CACHE_WARNING) + njit_funcs = get_njit_funcs() + + recompile_funcs = [] if func is None: - njit_funcs = 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) - func.recompile() + recompile_funcs.append(func) + elif func in njit_funcs: + recompile_funcs.append(func) else: - if not numba.extending.is_jitted(func): - msg = "The function `func` must be a (n)jit function." - raise ValueError(msg) + msg = "The function `func` is not a njit function in STUMPY" + raise ValueError(msg) + + for func in recompile_funcs: if fastmath is not None: func.targetoptions["fastmath"] = fastmath func.recompile() From 6854b0e50d7ca5646097b753346b8f17a6a74b3a Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 26 Dec 2024 00:23:19 -0500 Subject: [PATCH 17/68] renamed variable to improve readability --- stumpy/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stumpy/config.py b/stumpy/config.py index aa50d5de2..8a64c34fc 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -54,8 +54,8 @@ def _reset(var=None): ] if var is None: - for v in config_vars: - globals()[v] = _STUMPY_DEFAULTS[v] + for config_var in config_vars: + globals()[config_var] = _STUMPY_DEFAULTS[config_var] elif var in config_vars: globals()[var] = _STUMPY_DEFAULTS[var] else: From aeea9b4a993827a87a1d4c3f473ddc7f77054f53 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 26 Dec 2024 00:48:36 -0500 Subject: [PATCH 18/68] fixed bug --- stumpy/cache.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 7427839bb..9b8383490 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -129,14 +129,15 @@ def _recompile(func=None, fastmath=None): None """ warnings.warn(CACHE_WARNING) - njit_funcs = get_njit_funcs() + + njit_funcs = [] + for module_name, func_name in get_njit_funcs(): + module = importlib.import_module(f".{module_name}", package="stumpy") + njit_funcs.append(getattr(module, func_name)) recompile_funcs = [] if func is None: - for module_name, func_name in njit_funcs: - module = importlib.import_module(f".{module_name}", package="stumpy") - func = getattr(module, func_name) - recompile_funcs.append(func) + recompile_funcs = njit_funcs elif func in njit_funcs: recompile_funcs.append(func) else: From b41cc66a54746ddb2f887150252bca000c7d14bf Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 00:49:58 -0500 Subject: [PATCH 19/68] rename config to improve readability --- stumpy/aamp.py | 4 ++-- stumpy/config.py | 4 ++-- stumpy/core.py | 16 ++++++++-------- stumpy/maamp.py | 2 +- stumpy/mstump.py | 2 +- stumpy/scraamp.py | 4 ++-- stumpy/scrump.py | 4 ++-- stumpy/stump.py | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/stumpy/aamp.py b/stumpy/aamp.py index 02504ec0f..1e4879bcc 100644 --- a/stumpy/aamp.py +++ b/stumpy/aamp.py @@ -13,7 +13,7 @@ @njit( # "(f8[:], f8[:], i8, b1[:], b1[:], f8, i8[:], i8, i8, i8, f8[:, :, :]," # "f8[:, :], f8[:, :], i8[:, :, :], i8[:, :], i8[:, :], b1)", - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _compute_diagonal( T_A, @@ -186,7 +186,7 @@ def _compute_diagonal( @njit( # "(f8[:], f8[:], i8, b1[:], b1[:], i8[:], b1, i8)", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _aamp( T_A, diff --git a/stumpy/config.py b/stumpy/config.py index 8a64c34fc..ec35b76b3 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -17,7 +17,7 @@ "STUMPY_MAX_P_NORM_DISTANCE": np.finfo(np.float64).max, "STUMPY_MAX_DISTANCE": np.sqrt(np.finfo(np.float64).max), "STUMPY_EXCL_ZONE_DENOM": 4, - "STUMPY_FASTMATH": True, + "STUMPY_FASTMATH_TRUE": True, "STUMPY_FASTMATH_FLAGS": {"nsz", "arcp", "contract", "afn", "reassoc"}, } @@ -31,7 +31,7 @@ STUMPY_MAX_P_NORM_DISTANCE = _STUMPY_DEFAULTS["STUMPY_MAX_P_NORM_DISTANCE"] STUMPY_MAX_DISTANCE = _STUMPY_DEFAULTS["STUMPY_MAX_DISTANCE"] STUMPY_EXCL_ZONE_DENOM = _STUMPY_DEFAULTS["STUMPY_EXCL_ZONE_DENOM"] -STUMPY_FASTMATH = _STUMPY_DEFAULTS["STUMPY_FASTMATH"] +STUMPY_FASTMATH_TRUE = _STUMPY_DEFAULTS["STUMPY_FASTMATH_TRUE"] STUMPY_FASTMATH_FLAGS = _STUMPY_DEFAULTS["STUMPY_FASTMATH_FLAGS"] diff --git a/stumpy/core.py b/stumpy/core.py index a2801410d..e015c6d8b 100644 --- a/stumpy/core.py +++ b/stumpy/core.py @@ -589,7 +589,7 @@ def check_window_size(m, max_size=None): raise ValueError(f"The window size must be less than or equal to {max_size}") -@njit(fastmath=config.STUMPY_FASTMATH) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _sliding_dot_product(Q, T): """ A Numba JIT-compiled implementation of the sliding window dot product. @@ -1110,7 +1110,7 @@ def _calculate_squared_distance( @njit( # "f8[:](i8, f8[:], f8, f8, f8[:], f8[:])", - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _calculate_squared_distance_profile( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant @@ -1176,7 +1176,7 @@ def _calculate_squared_distance_profile( @njit( # "f8[:](i8, f8[:], f8, f8, f8[:], f8[:])", - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def calculate_distance_profile( m, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant @@ -1229,7 +1229,7 @@ def calculate_distance_profile( return np.sqrt(D_squared) -@njit(fastmath=config.STUMPY_FASTMATH) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _p_norm_distance_profile(Q, T, p=2.0): """ A Numba JIT-compiled and parallelized function for computing the p-normalized @@ -1505,7 +1505,7 @@ def mueen_calculate_distance_profile(Q, T): @njit( # "f8[:](f8[:], f8[:], f8[:], f8, f8, f8[:], f8[:])", - fastmath=config.STUMPY_FASTMATH + fastmath=config.STUMPY_FASTMATH_TRUE ) def _mass(Q, T, QT, μ_Q, σ_Q, M_T, Σ_T, Q_subseq_isconstant, T_subseq_isconstant): """ @@ -1978,7 +1978,7 @@ def _get_QT(start, T_A, T_B, m): @njit( # ["(f8[:], i8, i8)", "(f8[:, :], i8, i8)"], - fastmath=config.STUMPY_FASTMATH + fastmath=config.STUMPY_FASTMATH_TRUE ) def _apply_exclusion_zone(a, idx, excl_zone, val): """ @@ -2308,7 +2308,7 @@ def array_to_temp_file(a): @njit( # "i8[:](i8[:], i8, i8, i8)", - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _count_diagonal_ndist(diags, m, n_A, n_B): """ @@ -2842,7 +2842,7 @@ def _idx_to_mp( return P -@njit(fastmath=config.STUMPY_FASTMATH) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _total_diagonal_ndists(tile_lower_diag, tile_upper_diag, tile_height, tile_width): """ Count the total number of distances covered by a range of diagonals diff --git a/stumpy/maamp.py b/stumpy/maamp.py index 35fe5fdb8..e1038743f 100644 --- a/stumpy/maamp.py +++ b/stumpy/maamp.py @@ -592,7 +592,7 @@ def _get_multi_p_norm(start, T, m, p=2.0): # "(i8, i8, i8, f8[:, :], f8[:, :], i8, i8, b1[:, :], b1[:, :], f8," # "f8[:, :], f8[:, :], f8[:, :])", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _compute_multi_p_norm( d, diff --git a/stumpy/mstump.py b/stumpy/mstump.py index 44950106e..897490efa 100644 --- a/stumpy/mstump.py +++ b/stumpy/mstump.py @@ -811,7 +811,7 @@ def _get_multi_QT(start, T, m): # "(i8, i8, i8, f8[:, :], f8[:, :], i8, i8, f8[:, :], f8[:, :], f8[:, :]," # "f8[:, :], f8[:, :], f8[:, :], f8[:, :])", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _compute_multi_D( d, diff --git a/stumpy/scraamp.py b/stumpy/scraamp.py index c85c7fa6d..56d83f6b6 100644 --- a/stumpy/scraamp.py +++ b/stumpy/scraamp.py @@ -83,7 +83,7 @@ def _preprocess_prescraamp(T_A, m, T_B=None, s=None): return (T_A, T_B, T_A_subseq_isfinite, T_B_subseq_isfinite, indices, s, excl_zone) -@njit(fastmath=config.STUMPY_FASTMATH) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _compute_PI( T_A, T_B, @@ -286,7 +286,7 @@ def _compute_PI( # "(f8[:], f8[:], i8, b1[:], b1[:], f8, i8, i8, f8[:], f8[:]," # "i8[:], optional(i8))", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _prescraamp( T_A, diff --git a/stumpy/scrump.py b/stumpy/scrump.py index 601fc9d8e..dd5617480 100644 --- a/stumpy/scrump.py +++ b/stumpy/scrump.py @@ -133,7 +133,7 @@ def _preprocess_prescrump( ) -@njit(fastmath=config.STUMPY_FASTMATH) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _compute_PI( T_A, T_B, @@ -384,7 +384,7 @@ def _compute_PI( # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], i8, i8, f8[:], f8[:]," # "i8[:], optional(i8))", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _prescrump( T_A, diff --git a/stumpy/stump.py b/stumpy/stump.py index dc435c2e4..18409c6e1 100644 --- a/stumpy/stump.py +++ b/stumpy/stump.py @@ -15,7 +15,7 @@ # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], f8[:]," # "b1[:], b1[:], b1[:], b1[:], i8[:], i8, i8, i8, f8[:, :, :], f8[:, :]," # "f8[:, :], i8[:, :, :], i8[:, :], i8[:, :], b1)", - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _compute_diagonal( T_A, @@ -247,7 +247,7 @@ def _compute_diagonal( # "(f8[:], f8[:], i8, f8[:], f8[:], f8[:], f8[:], f8[:], f8[:], b1[:], b1[:]," # "b1[:], b1[:], i8[:], b1, i8)", parallel=True, - fastmath=config.STUMPY_FASTMATH, + fastmath=config.STUMPY_FASTMATH_TRUE, ) def _stump( T_A, From 02b1fb434b65eabeec2af2ca947c5f9a5ecb2551 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 01:09:14 -0500 Subject: [PATCH 20/68] revise func clear --- stumpy/cache.py | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 9b8383490..867ef7909 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -111,42 +111,20 @@ def _get_cache(): def _recompile(func=None, fastmath=None): """ - Recompile a jit/njit decorated function. If `func` is None, then it will - recompile all njit functions of STUMPY. + Recompile all njit functions Parameters ---------- - func : a njit function, default None - The numba function to recompile. If None, then all njit functions - of STUMPY will be recompiled. - - fastmath : bool or set, default None - The fastmath flags to use. If None, then the func's fastmath flags - will not be changed. This is only used when `func` is provided. + None Returns ------- None """ warnings.warn(CACHE_WARNING) - - njit_funcs = [] for module_name, func_name in get_njit_funcs(): module = importlib.import_module(f".{module_name}", package="stumpy") - njit_funcs.append(getattr(module, func_name)) - - recompile_funcs = [] - if func is None: - recompile_funcs = njit_funcs - elif func in njit_funcs: - recompile_funcs.append(func) - else: - msg = "The function `func` is not a njit function in STUMPY" - raise ValueError(msg) - - for func in recompile_funcs: - if fastmath is not None: - func.targetoptions["fastmath"] = fastmath + func = getattr(module, func_name) func.recompile() return From 964711362602dbf93c5cd94a8507a7d6c0f181f8 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 01:10:11 -0500 Subject: [PATCH 21/68] revise func to recompile all njit functions --- stumpy/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 867ef7909..d01eab7c7 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -109,7 +109,7 @@ def _get_cache(): return [f.name for f in pathlib.Path(numba_cache_dir).glob("*nb*") if f.is_file()] -def _recompile(func=None, fastmath=None): +def _recompile(): """ Recompile all njit functions From 245bfc42143dc5ddbe806803702ee29f14157458 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 01:57:12 -0500 Subject: [PATCH 22/68] Adapt to changes in test function --- tests/test_precision.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index 784121d40..40946b74c 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -151,10 +151,12 @@ def test_snippets(): if not np.allclose(ref_snippets, cmp_snippets) and not numba.config.DISABLE_JIT: # Revise fastmath flags by removing reassoc (to improve precision), # recompile njit functions, and re-compute snippets. - config.STUMPY_FASTMATH_FLAGS = {"nsz", "arcp", "contract", "afn"} - cache._recompile( - core._calculate_squared_distance, fastmath=config.STUMPY_FASTMATH_FLAGS - ) + core._calculate_squared_distance.targetoptions["fastmath"] = { + "nsz", + "arcp", + "contract", + "afn", + } cache._recompile() ( @@ -186,8 +188,8 @@ def test_snippets(): if not numba.config.DISABLE_JIT: # Revert fastmath flag back to their default values config._reset("STUMPY_FASTMATH_FLAGS") - cache._recompile( - core._calculate_squared_distance, fastmath=config.STUMPY_FASTMATH_FLAGS + core._calculate_squared_distance.targetoptions["fastmath"] = ( + config.STUMPY_FASTMATH_FLAGS ) cache._recompile() From 7dd15eb810481f083a9d7754a8c4806d6bc6aae6 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 02:03:40 -0500 Subject: [PATCH 23/68] add test --- tests/test_config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 2ee09d996..3b5dfe242 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -9,3 +9,12 @@ def test_change_excl_zone_denom(): config.STUMPY_EXCL_ZONE_DENOM = 4 assert core.get_max_window_size(10) == 7 + + +def test_reset(): + ref = config.STUMPY_EXCL_ZONE_DENOM + + config.STUMPY_EXCL_ZONE_DENOM += 1 + config._reset("STUMPY_EXCL_ZONE_DENOM") + + assert config.STUMPY_EXCL_ZONE_DENOM == ref From 4b52ff53c4ed4914bc022a414524b57335c99b5e Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 02:05:37 -0500 Subject: [PATCH 24/68] resolve coverage --- tests/test_precision.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index 40946b74c..706842b33 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -148,7 +148,9 @@ def test_snippets(): cmp_regimes, ) = stumpy.snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func) - if not np.allclose(ref_snippets, cmp_snippets) and not numba.config.DISABLE_JIT: + if ( + not np.allclose(ref_snippets, cmp_snippets) and not numba.config.DISABLE_JIT + ): # pragma: no cover # Revise fastmath flags by removing reassoc (to improve precision), # recompile njit functions, and re-compute snippets. core._calculate_squared_distance.targetoptions["fastmath"] = { @@ -185,7 +187,7 @@ def test_snippets(): npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION) npt.assert_almost_equal(ref_regimes, cmp_regimes) - if not numba.config.DISABLE_JIT: + if not numba.config.DISABLE_JIT: # pragma: no cover # Revert fastmath flag back to their default values config._reset("STUMPY_FASTMATH_FLAGS") core._calculate_squared_distance.targetoptions["fastmath"] = ( From aabd41aeae208253ee0adee98448726b6a5dbbd7 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 02:31:24 -0500 Subject: [PATCH 25/68] resolve missing lines in coverage --- stumpy/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/config.py b/stumpy/config.py index ec35b76b3..68eabaa04 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -58,7 +58,7 @@ def _reset(var=None): globals()[config_var] = _STUMPY_DEFAULTS[config_var] elif var in config_vars: globals()[var] = _STUMPY_DEFAULTS[var] - else: + else: # pragma: no cover msg = f'Could not reset unrecognized configuration variable "{var}"' warnings.warn(msg) From 47c99328ff3ab28615a846ccb69e894e2da9f196 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 28 Dec 2024 02:36:05 -0500 Subject: [PATCH 26/68] Add test function to improve coverage --- tests/test_config.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 3b5dfe242..e2e2412fc 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -11,10 +11,22 @@ def test_change_excl_zone_denom(): assert core.get_max_window_size(10) == 7 -def test_reset(): +def test_reset_one_var(): ref = config.STUMPY_EXCL_ZONE_DENOM config.STUMPY_EXCL_ZONE_DENOM += 1 config._reset("STUMPY_EXCL_ZONE_DENOM") assert config.STUMPY_EXCL_ZONE_DENOM == ref + + +def test_reset_all_vars(): + ref_fastmath = config.STUMPY_FASTMATH_TRUE + ref_excl_zone_denom = config.STUMPY_EXCL_ZONE_DENOM + + config.STUMPY_FASTMATH_TRUE = not config.STUMPY_FASTMATH_TRUE + config.STUMPY_EXCL_ZONE_DENOM += 1 + + config._reset() + assert config.STUMPY_FASTMATH_TRUE == ref_fastmath + assert config.STUMPY_EXCL_ZONE_DENOM == ref_excl_zone_denom From 816e8d405b8f13f50f7a85aa5100d6e8dee1184d Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 29 Dec 2024 15:13:45 -0500 Subject: [PATCH 27/68] add fastmath module --- stumpy/fastmath.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 stumpy/fastmath.py diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py new file mode 100644 index 000000000..d4a0c33af --- /dev/null +++ b/stumpy/fastmath.py @@ -0,0 +1,90 @@ +import ast +import importlib +import pathlib + +from stumpy import config + + +def get_default_fastmath(module_name): + """ + Retrieve a dictionary where key is njit function name + and value is the default fastmath flag. + + Parameters + ---------- + module_name : str + The module name + + Returns + ------- + out : dict + A dictionary of njit functions, where key is the function name + and value is the fastmath flag. + """ + filepath = pathlib.Path(__file__).parent / f"{module_name}.py" + file_contents = "" + with open(filepath, encoding="utf8") as f: + file_contents = f.read() + + out = {} + module = ast.parse(file_contents) + for node in module.body: + if not isinstance(node, ast.FunctionDef): + continue + + func_name = node.name + for decorator in node.decorator_list: + if not isinstance(decorator, ast.Call) or not isinstance( + decorator.func, ast.Name + ): + continue + + if decorator.func.id != "njit": + continue + + fastmath_default = None + for item in decorator.keywords: + if item.arg == "fastmath": + config_var = item.value.attr + fastmath_default = config._STUMPY_DEFAULTS[config_var] + break + + out[func_name] = fastmath_default + + return out + + +def set_flag(module_name, func_name, flag=None): + """ + Set a flag for a given function + + Parameters + ---------- + module_name : str + The module name + func_name : str + The function name + flag : str + The flag to set + + Returns + ------- + None + """ + module = importlib.import_module(f".{module_name}", package="stumpy") + func = getattr(module, func_name) + + funcs_flags = get_default_fastmath(module_name) + if func_name not in funcs_flags.keys(): + msg = "The module `{module_name}` does not have a njit function `{func_name}`" + raise ValueError(msg) + default_flag = funcs_flags[func_name] + + if flag is None: + flag = default_flag + + if flag is not None: + func.targetoptions["fastmath"] = flag + func.recompile() + + return From 562550e53a8ab60d7b189eddcf68ee2908c161f2 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 29 Dec 2024 15:16:13 -0500 Subject: [PATCH 28/68] revise test function to use fastmath module --- tests/test_precision.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index 706842b33..efd5d6000 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -9,7 +9,7 @@ from numba import cuda import stumpy -from stumpy import cache, config, core +from stumpy import cache, config, core, fastmath try: from numba.errors import NumbaPerformanceWarning @@ -153,14 +153,10 @@ def test_snippets(): ): # pragma: no cover # Revise fastmath flags by removing reassoc (to improve precision), # recompile njit functions, and re-compute snippets. - core._calculate_squared_distance.targetoptions["fastmath"] = { - "nsz", - "arcp", - "contract", - "afn", - } + fastmath.set_flag( + "core", "_calculate_squared_distance", {"nsz", "arcp", "contract", "afn"} + ) cache._recompile() - ( cmp_snippets, cmp_indices, @@ -189,10 +185,7 @@ def test_snippets(): if not numba.config.DISABLE_JIT: # pragma: no cover # Revert fastmath flag back to their default values - config._reset("STUMPY_FASTMATH_FLAGS") - core._calculate_squared_distance.targetoptions["fastmath"] = ( - config.STUMPY_FASTMATH_FLAGS - ) + fastmath.set_flag("core", "_calculate_squared_distance") cache._recompile() From d99148a296991b70cc42c7226ea2b0ceb352395d Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 29 Dec 2024 15:19:07 -0500 Subject: [PATCH 29/68] fix minor issue --- stumpy/fastmath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index d4a0c33af..98d7e3865 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -76,7 +76,7 @@ def set_flag(module_name, func_name, flag=None): funcs_flags = get_default_fastmath(module_name) if func_name not in funcs_flags.keys(): - msg = "The module `{module_name}` does not have a njit function `{func_name}`" + msg = f"The module `{module_name}` does not have a njit function `{func_name}`" raise ValueError(msg) default_flag = funcs_flags[func_name] From 8a45f6ecca5578b7ccb71e366d80c96b6f6c04dc Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 29 Dec 2024 15:37:38 -0500 Subject: [PATCH 30/68] minor change to improve readability --- stumpy/fastmath.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index 98d7e3865..538596db4 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -71,9 +71,6 @@ def set_flag(module_name, func_name, flag=None): ------- None """ - module = importlib.import_module(f".{module_name}", package="stumpy") - func = getattr(module, func_name) - funcs_flags = get_default_fastmath(module_name) if func_name not in funcs_flags.keys(): msg = f"The module `{module_name}` does not have a njit function `{func_name}`" @@ -84,6 +81,8 @@ def set_flag(module_name, func_name, flag=None): flag = default_flag if flag is not None: + module = importlib.import_module(f".{module_name}", package="stumpy") + func = getattr(module, func_name) func.targetoptions["fastmath"] = flag func.recompile() From 7eb52c12f927a1619228805d94b9d6aa0f936f0e Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 3 Jan 2025 23:12:19 -0500 Subject: [PATCH 31/68] Add fastmath default flags to config default --- stumpy/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stumpy/__init__.py b/stumpy/__init__.py index 76a5cfbad..8fe825c28 100644 --- a/stumpy/__init__.py +++ b/stumpy/__init__.py @@ -1,9 +1,11 @@ import os.path +import importlib from importlib.metadata import distribution from site import getsitepackages from numba import cuda +from . import cache, config from .aamp import aamp # noqa: F401 from .aamp_mmotifs import aamp_mmotifs # noqa: F401 from .aamp_motifs import aamp_match, aamp_motifs # noqa: F401 @@ -32,6 +34,16 @@ from .stumped import stumped # noqa: F401 from .stumpi import stumpi # noqa: F401 +# Get the default fastmath flags for all njit functions +# and update the _STUMPY_DEFAULTS dictionary +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) + key = module_name + '.' + func_name # e.g., core._mass + key = 'STUMPY_FASTMATH_' + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS + config._STUMPY_DEFAULTS[key] = func.targetoptions['fastmath'] + if cuda.is_available(): from .gpu_aamp import gpu_aamp # noqa: F401 from .gpu_aamp_ostinato import gpu_aamp_ostinato # noqa: F401 From b130fa75cdaed5c2b5dad690ddf72b07797868ca Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 3 Jan 2025 23:25:10 -0500 Subject: [PATCH 32/68] add reset function --- stumpy/fastmath.py | 72 +++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 49 deletions(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index 538596db4..7094f77fc 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -5,55 +5,6 @@ from stumpy import config -def get_default_fastmath(module_name): - """ - Retrieve a dictionary where key is njit function name - and value is the default fastmath flag. - - Parameters - ---------- - module_name : str - The module name - - Returns - ------- - out : dict - A dictionary of njit functions, where key is the function name - and value is the fastmath flag. - """ - filepath = pathlib.Path(__file__).parent / f"{module_name}.py" - file_contents = "" - with open(filepath, encoding="utf8") as f: - file_contents = f.read() - - out = {} - module = ast.parse(file_contents) - for node in module.body: - if not isinstance(node, ast.FunctionDef): - continue - - func_name = node.name - for decorator in node.decorator_list: - if not isinstance(decorator, ast.Call) or not isinstance( - decorator.func, ast.Name - ): - continue - - if decorator.func.id != "njit": - continue - - fastmath_default = None - for item in decorator.keywords: - if item.arg == "fastmath": - config_var = item.value.attr - fastmath_default = config._STUMPY_DEFAULTS[config_var] - break - - out[func_name] = fastmath_default - - return out - - def set_flag(module_name, func_name, flag=None): """ Set a flag for a given function @@ -87,3 +38,26 @@ def set_flag(module_name, func_name, flag=None): func.recompile() return + + +def _reset(module_name, func_name): + """ + Reset the value of fastmath its default value + + Parameters + ---------- + module_name : str + The module name + func_name : str + The function name + + Returns + ------- + None + """ + key = module_name + "." + func_name + key = "STUMPY_FASTMATH_" + key.upper() + default_flag = config._STUMPY_DEFAULTS[key] + set_flag(module_name, func_name, default_flag) + + return From 6264e942ad1262f016a131e53a4d5cbf5eda2a52 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 3 Jan 2025 23:44:48 -0500 Subject: [PATCH 33/68] rename function --- stumpy/fastmath.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index 7094f77fc..e852e4f46 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -1,13 +1,11 @@ -import ast import importlib -import pathlib from stumpy import config -def set_flag(module_name, func_name, flag=None): +def _set(module_name, func_name, flag): """ - Set a flag for a given function + Set fastmath flag for a given function Parameters ---------- @@ -15,27 +13,17 @@ def set_flag(module_name, func_name, flag=None): The module name func_name : str The function name - flag : str - The flag to set + flag : set or bool + The fastmath flag Returns ------- None """ - funcs_flags = get_default_fastmath(module_name) - if func_name not in funcs_flags.keys(): - msg = f"The module `{module_name}` does not have a njit function `{func_name}`" - raise ValueError(msg) - default_flag = funcs_flags[func_name] - - if flag is None: - flag = default_flag - - if flag is not None: - module = importlib.import_module(f".{module_name}", package="stumpy") - func = getattr(module, func_name) - func.targetoptions["fastmath"] = flag - func.recompile() + module = importlib.import_module(f".{module_name}", package="stumpy") + func = getattr(module, func_name) + func.targetoptions["fastmath"] = flag + func.recompile() return @@ -58,6 +46,6 @@ def _reset(module_name, func_name): key = module_name + "." + func_name key = "STUMPY_FASTMATH_" + key.upper() default_flag = config._STUMPY_DEFAULTS[key] - set_flag(module_name, func_name, default_flag) + _set(module_name, func_name, default_flag) return From 1d873bda000885e10e299bf0d4af08b86b861963 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 3 Jan 2025 23:49:51 -0500 Subject: [PATCH 34/68] adapt recent changes in test function --- tests/test_precision.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_precision.py b/tests/test_precision.py index efd5d6000..12a4481f8 100644 --- a/tests/test_precision.py +++ b/tests/test_precision.py @@ -153,10 +153,11 @@ def test_snippets(): ): # pragma: no cover # Revise fastmath flags by removing reassoc (to improve precision), # recompile njit functions, and re-compute snippets. - fastmath.set_flag( + fastmath._set( "core", "_calculate_squared_distance", {"nsz", "arcp", "contract", "afn"} ) cache._recompile() + ( cmp_snippets, cmp_indices, @@ -185,7 +186,7 @@ def test_snippets(): if not numba.config.DISABLE_JIT: # pragma: no cover # Revert fastmath flag back to their default values - fastmath.set_flag("core", "_calculate_squared_distance") + fastmath._reset("core", "_calculate_squared_distance") cache._recompile() From 127e61c1b7c6b97371cf0c2057cec3166f3cd8e9 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 3 Jan 2025 23:57:31 -0500 Subject: [PATCH 35/68] minor fixes --- stumpy/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stumpy/__init__.py b/stumpy/__init__.py index 8fe825c28..fab3da8c1 100644 --- a/stumpy/__init__.py +++ b/stumpy/__init__.py @@ -1,5 +1,5 @@ -import os.path import importlib +import os.path from importlib.metadata import distribution from site import getsitepackages @@ -40,9 +40,9 @@ for module_name, func_name in njit_funcs: module = importlib.import_module(f".{module_name}", package="stumpy") func = getattr(module, func_name) - key = module_name + '.' + func_name # e.g., core._mass - key = 'STUMPY_FASTMATH_' + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS - config._STUMPY_DEFAULTS[key] = func.targetoptions['fastmath'] + key = module_name + "." + func_name # e.g., core._mass + key = "STUMPY_FASTMATH_" + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS + config._STUMPY_DEFAULTS[key] = func.targetoptions.get("fastmath", False) if cuda.is_available(): from .gpu_aamp import gpu_aamp # noqa: F401 From 447c006590b1382e0c7783733b7273477224c908 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 4 Jan 2025 09:04:58 -0500 Subject: [PATCH 36/68] Check if DISABLE_JIT before getting fastmath --- stumpy/__init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/stumpy/__init__.py b/stumpy/__init__.py index fab3da8c1..48e6a8771 100644 --- a/stumpy/__init__.py +++ b/stumpy/__init__.py @@ -3,6 +3,7 @@ from importlib.metadata import distribution from site import getsitepackages +import numba from numba import cuda from . import cache, config @@ -36,13 +37,15 @@ # Get the default fastmath flags for all njit functions # and update the _STUMPY_DEFAULTS dictionary -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) - key = module_name + "." + func_name # e.g., core._mass - key = "STUMPY_FASTMATH_" + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS - config._STUMPY_DEFAULTS[key] = func.targetoptions.get("fastmath", False) + +if not numba.config.DISABLE_JIT: + 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) + key = module_name + "." + func_name # e.g., core._mass + key = "STUMPY_FASTMATH_" + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS + config._STUMPY_DEFAULTS[key] = func.targetoptions.get("fastmath", False) if cuda.is_available(): from .gpu_aamp import gpu_aamp # noqa: F401 From 14c2267a786c222422a699825762b8736d505e6b Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sat, 4 Jan 2025 09:28:29 -0500 Subject: [PATCH 37/68] ignore lines for coverage check --- stumpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/__init__.py b/stumpy/__init__.py index 48e6a8771..d61ba0cdf 100644 --- a/stumpy/__init__.py +++ b/stumpy/__init__.py @@ -38,7 +38,7 @@ # Get the default fastmath flags for all njit functions # and update the _STUMPY_DEFAULTS dictionary -if not numba.config.DISABLE_JIT: +if not numba.config.DISABLE_JIT: # pragma: no cover njit_funcs = cache.get_njit_funcs() for module_name, func_name in njit_funcs: module = importlib.import_module(f".{module_name}", package="stumpy") From 2469458c75e181631bbb573d3a8b47932cdef19b Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 18:14:28 -0500 Subject: [PATCH 38/68] Editorial fix --- stumpy/fastmath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index e852e4f46..e2d6f8ce7 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -30,7 +30,7 @@ def _set(module_name, func_name, flag): def _reset(module_name, func_name): """ - Reset the value of fastmath its default value + Reset the value of fastmath to its default value Parameters ---------- From 262444537c30a81283855e7c03a2b21178ceab03 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 18:21:18 -0500 Subject: [PATCH 39/68] avoid .get(key) to get KeyError if it does not exist --- stumpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/__init__.py b/stumpy/__init__.py index d61ba0cdf..870912b15 100644 --- a/stumpy/__init__.py +++ b/stumpy/__init__.py @@ -45,7 +45,7 @@ func = getattr(module, func_name) key = module_name + "." + func_name # e.g., core._mass key = "STUMPY_FASTMATH_" + key.upper() # e.g., STUMPY_FASTHMATH_CORE._MASS - config._STUMPY_DEFAULTS[key] = func.targetoptions.get("fastmath", False) + config._STUMPY_DEFAULTS[key] = func.targetoptions["fastmath"] if cuda.is_available(): from .gpu_aamp import gpu_aamp # noqa: F401 From 4b37b0a27095b04b25e482062e0e35a3ae5cfde2 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 19:06:38 -0500 Subject: [PATCH 40/68] add function to save cache --- stumpy/cache.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/stumpy/cache.py b/stumpy/cache.py index d3819c257..5b6f53519 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -138,3 +138,25 @@ def _recompile(): func.recompile() return + + +def _save(): + """ + Save all njit functions + + Parameters + ---------- + None + + Returns + ------- + None + """ + warnings.filterwarnings("once") + warnings.warn(CACHE_WARNING) + _enable() + _recompile() + warnings.filterwarnings("default") + + + return \ No newline at end of file From baf3feacebaabd9b60e4a384a4eedb4beec46225 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 19:21:21 -0500 Subject: [PATCH 41/68] Add note to function --- stumpy/cache.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stumpy/cache.py b/stumpy/cache.py index 5b6f53519..074550030 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -130,6 +130,11 @@ def _recompile(): Returns ------- None + + Notes + ----- + If the `numba` cache is enabled, this results in saving (and/or overwriting) + the cached numba functions to disk. """ warnings.warn(CACHE_WARNING) for module_name, func_name in get_njit_funcs(): From 7d021733a2120c40d863c44832939b3a35ed7352 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 19:24:07 -0500 Subject: [PATCH 42/68] fix format --- stumpy/cache.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index 074550030..0ed0cb3a3 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -134,7 +134,7 @@ def _recompile(): Notes ----- If the `numba` cache is enabled, this results in saving (and/or overwriting) - the cached numba functions to disk. + the cached numba functions to disk. """ warnings.warn(CACHE_WARNING) for module_name, func_name in get_njit_funcs(): @@ -162,6 +162,5 @@ def _save(): _enable() _recompile() warnings.filterwarnings("default") - - return \ No newline at end of file + return From 24bc23265ef6334b05b5c60283d7af29ad6ee472 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 12 Jan 2025 21:17:44 -0500 Subject: [PATCH 43/68] replace fastmath flag with config variable --- stumpy/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stumpy/core.py b/stumpy/core.py index 61e1c31a0..28f532ff3 100644 --- a/stumpy/core.py +++ b/stumpy/core.py @@ -2356,7 +2356,7 @@ def _count_diagonal_ndist(diags, m, n_A, n_B): @njit( # "i8[:, :](i8[:], i8, b1)" - fastmath=True + fastmath=config.STUMPY_FASTMATH_TRUE ) def _get_array_ranges(a, n_chunks, truncate): """ @@ -2405,7 +2405,7 @@ def _get_array_ranges(a, n_chunks, truncate): @njit( # "i8[:, :](i8, i8, b1)" - fastmath=True + fastmath=config.STUMPY_FASTMATH_TRUE ) def _get_ranges(size, n_chunks, truncate): """ @@ -3258,7 +3258,7 @@ def _select_P_ABBA_value(P_ABBA, k, custom_func=None): return MPdist -@njit(fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(fastmath=config.STUMPY_FASTMATH_FLAGS) def _merge_topk_PI(PA, PB, IA, IB): """ Merge two top-k matrix profiles `PA` and `PB`, and update `PA` (in place). @@ -3331,7 +3331,7 @@ def _merge_topk_PI(PA, PB, IA, IB): IA[i] = tmp_I -@njit(fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(fastmath=config.STUMPY_FASTMATH_FLAGS) def _merge_topk_ρI(ρA, ρB, IA, IB): """ Merge two top-k pearson profiles `ρA` and `ρB`, and update `ρA` (in place). @@ -3405,7 +3405,7 @@ def _merge_topk_ρI(ρA, ρB, IA, IB): IA[i] = tmp_I -@njit(fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(fastmath=config.STUMPY_FASTMATH_FLAGS) def _shift_insert_at_index(a, idx, v, shift="right"): """ If `shift=right` (default), all elements in `a[idx:]` are shifted to the right by @@ -4381,7 +4381,7 @@ def get_ray_nworkers(ray_client): return int(ray_client.cluster_resources().get("CPU")) -@njit(fastmath={"nsz", "arcp", "contract", "afn", "reassoc"}) +@njit(fastmath=config.STUMPY_FASTMATH_FLAGS) def _update_incremental_PI(D, P, I, excl_zone, n_appended=0): """ Given the 1D array distance profile, `D`, of the last subsequence of T, From f5c271876da5766284548cc2c22a2cf9f055aa5c Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 15 Jan 2025 08:59:32 -0500 Subject: [PATCH 44/68] add test function to check backward compatibility --- tests/test_cache.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test_cache.py diff --git a/tests/test_cache.py b/tests/test_cache.py new file mode 100644 index 000000000..7b2c94691 --- /dev/null +++ b/tests/test_cache.py @@ -0,0 +1,41 @@ +import numpy as np + +from stumpy import cache, stump + + +def test_cache_save(): + def get_cache_fnames_ref(): + cache._clear() + cache._enable() + stump(np.random.rand(10), 3) + cache_data_fnames = [ + fname for fname in cache._get_cache() if fname.endswith(".nbc") + ] + cache_index_fnames = [ + fname for fname in cache._get_cache() if fname.endswith(".nbi") + ] + cache._clear() + return cache_data_fnames, cache_index_fnames + + def get_cache_fnames_comp(): + cache._clear() + cache._save() + stump(np.random.rand(10), 3) + cache_data_fnames = [ + fname for fname in cache._get_cache() if fname.endswith(".nbc") + ] + cache_index_fnames = [ + fname for fname in cache._get_cache() if fname.endswith(".nbi") + ] + cache._clear() + return cache_data_fnames, cache_index_fnames + + ref_data, ref_index = get_cache_fnames_ref() + comp_data, comp_index = get_cache_fnames_comp() + + assert sorted(ref_data) == sorted(comp_data) + assert set(ref_index).issubset(comp_index) + + +if __name__ == "__main__": + test_cache_save() From 1a173469aa13375b058df15e311911e475887990 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 15 Jan 2025 15:27:01 -0500 Subject: [PATCH 45/68] skip test when JIT is disabled --- tests/test_cache.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index 7b2c94691..b86e5a3bc 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,7 +1,12 @@ +import numba import numpy as np +import pytest from stumpy import cache, stump +if numba.config.DISABLE_JIT: + pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True) + def test_cache_save(): def get_cache_fnames_ref(): @@ -35,7 +40,3 @@ def get_cache_fnames_comp(): assert sorted(ref_data) == sorted(comp_data) assert set(ref_index).issubset(comp_index) - - -if __name__ == "__main__": - test_cache_save() From 995a6c28254a2c5f5fd147ee108cd75a1b5fe412 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 16 Jan 2025 00:33:40 -0500 Subject: [PATCH 46/68] rename test function --- tests/test_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index b86e5a3bc..bed53046d 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -8,7 +8,7 @@ pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True) -def test_cache_save(): +def test_cache(): def get_cache_fnames_ref(): cache._clear() cache._enable() From 009795326deec302f0482fc329095f5debcd98be Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 16 Jan 2025 00:34:30 -0500 Subject: [PATCH 47/68] add conditional deprecation warning --- stumpy/cache.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stumpy/cache.py b/stumpy/cache.py index 0ed0cb3a3..fa39805a5 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -4,6 +4,7 @@ import ast import importlib +import inspect import pathlib import site import warnings @@ -74,6 +75,15 @@ def _enable(): ------- None """ + frame = inspect.currentframe() + caller_name = inspect.getouterframes(frame)[1].function + if caller_name != "_save": + msg = ( + "The 'cache._enable()' function is deprecated and no longer supported. " + + "Please use 'cache._save()' instead" + ) + warnings.warn(msg, DeprecationWarning, stacklevel=2) + warnings.warn(CACHE_WARNING) njit_funcs = get_njit_funcs() for module_name, func_name in njit_funcs: From bee3b63424cbde649143e820108a68aa34441657 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 16 Jan 2025 00:56:19 -0500 Subject: [PATCH 48/68] add test function to check if cache can be saved after cache._clear() --- tests/test_cache.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index bed53046d..dbf8f4de0 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -8,7 +8,7 @@ pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True) -def test_cache(): +def test_cache_save(): def get_cache_fnames_ref(): cache._clear() cache._enable() @@ -40,3 +40,18 @@ def get_cache_fnames_comp(): assert sorted(ref_data) == sorted(comp_data) assert set(ref_index).issubset(comp_index) + + +def test_cache_save_after_clear(): + T = np.random.rand(10) + m = 3 + stump(T, m) + + cache._save() + ref_cache = cache._get_cache() + + cache._clear() + cache._save() + comp_cache = cache._get_cache() + + assert sorted(ref_cache) == sorted(comp_cache) From 8d29f912ca2c0225ee0fc87514b4086d431e8878 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Thu, 16 Jan 2025 23:05:38 -0500 Subject: [PATCH 49/68] remove old warning --- stumpy/cache.py | 1 - 1 file changed, 1 deletion(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index fa39805a5..fbaf55ce4 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -84,7 +84,6 @@ def _enable(): ) warnings.warn(msg, DeprecationWarning, stacklevel=2) - warnings.warn(CACHE_WARNING) njit_funcs = get_njit_funcs() for module_name, func_name in njit_funcs: module = importlib.import_module(f".{module_name}", package="stumpy") From 18dd4b924c3f2e9bab861bfa2ae9ca5845d41f09 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 00:48:49 -0500 Subject: [PATCH 50/68] add test for cache._clear --- tests/test_cache.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_cache.py b/tests/test_cache.py index dbf8f4de0..de7715c2f 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -51,7 +51,11 @@ def test_cache_save_after_clear(): ref_cache = cache._get_cache() cache._clear() + # testing cache._clear() + assert len(cache._get_cache()) == 0 + cache._save() comp_cache = cache._get_cache() + # testing cache._save() after cache._clear() assert sorted(ref_cache) == sorted(comp_cache) From d7b21a7f63083cd252aa68c0b369699392229a7e Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 11:22:21 -0500 Subject: [PATCH 51/68] add wrapper around private functions --- stumpy/cache.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/stumpy/cache.py b/stumpy/cache.py index fbaf55ce4..b84e1d948 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -109,6 +109,23 @@ def _clear(): [f.unlink() for f in pathlib.Path(numba_cache_dir).glob("*nb*") if f.is_file()] +def clear(): + """ + Clear numba cache directory + + Parameters + ---------- + None + + Returns + ------- + None + """ + _clear() + + return + + def _get_cache(): """ Retrieve a list of cached numba functions @@ -173,3 +190,21 @@ def _save(): warnings.filterwarnings("default") return + + +def save(): + """ + Save/overwrite all the cache data files of + all-so-far compiled njit functions. + + Parameters + ---------- + None + + Returns + ------- + None + """ + _save() + + return From cf4b18342a0c6c4fa6cd303be88e88f715e8cd27 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 11:54:31 -0500 Subject: [PATCH 52/68] Raise OSError when NUMBA JIT is disabled during cache save --- stumpy/cache.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stumpy/cache.py b/stumpy/cache.py index b84e1d948..be157a2f8 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -9,6 +9,8 @@ import site import warnings +import numba + CACHE_WARNING = "Caching `numba` functions is purely for experimental purposes " CACHE_WARNING += "and should never be used or depended upon as it is not supported! " CACHE_WARNING += "All caching capabilities are not tested and may be removed/changed " @@ -205,6 +207,10 @@ def save(): ------- None """ + if numba.config.DISABLE_JIT: + msg = "Cannot save cache because NUMBA JIT is disabled" + raise OSError(msg) + _save() return From 89825c91376d28baa48a19ebae893580af149178 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 16:42:34 -0500 Subject: [PATCH 53/68] move warnings to public API --- stumpy/cache.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index be157a2f8..a94b2e905 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -105,7 +105,6 @@ def _clear(): ------- None """ - warnings.warn(CACHE_WARNING) site_pkg_dir = site.getsitepackages()[0] numba_cache_dir = site_pkg_dir + "/stumpy/__pycache__" [f.unlink() for f in pathlib.Path(numba_cache_dir).glob("*nb*") if f.is_file()] @@ -123,6 +122,7 @@ def clear(): ------- None """ + warnings.warn(CACHE_WARNING) _clear() return @@ -164,7 +164,6 @@ def _recompile(): If the `numba` cache is enabled, this results in saving (and/or overwriting) the cached numba functions to disk. """ - warnings.warn(CACHE_WARNING) for module_name, func_name in get_njit_funcs(): module = importlib.import_module(f".{module_name}", package="stumpy") func = getattr(module, func_name) @@ -185,11 +184,8 @@ def _save(): ------- None """ - warnings.filterwarnings("once") - warnings.warn(CACHE_WARNING) _enable() _recompile() - warnings.filterwarnings("default") return @@ -211,6 +207,7 @@ def save(): msg = "Cannot save cache because NUMBA JIT is disabled" raise OSError(msg) + warnings.warn(CACHE_WARNING) _save() return From 6a61483c36ba5f9e695e5891b8b7f14d4d150ad1 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 16:49:39 -0500 Subject: [PATCH 54/68] fix warning message --- stumpy/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index a94b2e905..e8be7b1de 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -82,7 +82,7 @@ def _enable(): if caller_name != "_save": msg = ( "The 'cache._enable()' function is deprecated and no longer supported. " - + "Please use 'cache._save()' instead" + + "Please use 'cache.save()' instead" ) warnings.warn(msg, DeprecationWarning, stacklevel=2) From fd7eb7d100749a2abe41b53849232689430aa581 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 20:48:17 -0500 Subject: [PATCH 55/68] improved warning message --- stumpy/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/config.py b/stumpy/config.py index 68eabaa04..93f11c2a2 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -59,7 +59,7 @@ def _reset(var=None): elif var in config_vars: globals()[var] = _STUMPY_DEFAULTS[var] else: # pragma: no cover - msg = f'Could not reset unrecognized configuration variable "{var}"' + msg = f"Configuration reset was skipped for unrecognized '_STUMPY_DEFAULT[{var}]'" warnings.warn(msg) return From 9ba634bf53f27c477dd0e7830f899db3c0839a3b Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Fri, 17 Jan 2025 21:01:30 -0500 Subject: [PATCH 56/68] Add commit about addition config variables that are defined in __init__ --- stumpy/config.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stumpy/config.py b/stumpy/config.py index 93f11c2a2..d66ff76eb 100644 --- a/stumpy/config.py +++ b/stumpy/config.py @@ -21,6 +21,12 @@ "STUMPY_FASTMATH_FLAGS": {"nsz", "arcp", "contract", "afn", "reassoc"}, } +# In addition to these configuration variables, there exist config variables +# that have the default value of the fastmath flag of the njit functions. The +# name of this config variable has the following format: +# STUMPY_FASTMATH_. +# See __init__.py for more details + STUMPY_THREADS_PER_BLOCK = _STUMPY_DEFAULTS["STUMPY_THREADS_PER_BLOCK"] STUMPY_MEAN_STD_NUM_CHUNKS = _STUMPY_DEFAULTS["STUMPY_MEAN_STD_NUM_CHUNKS"] STUMPY_MEAN_STD_MAX_ITER = _STUMPY_DEFAULTS["STUMPY_MEAN_STD_MAX_ITER"] @@ -59,7 +65,9 @@ def _reset(var=None): elif var in config_vars: globals()[var] = _STUMPY_DEFAULTS[var] else: # pragma: no cover - msg = f"Configuration reset was skipped for unrecognized '_STUMPY_DEFAULT[{var}]'" + msg = ( + f"Configuration reset was skipped for unrecognized '_STUMPY_DEFAULT[{var}]'" + ) warnings.warn(msg) return From 1a48f3d88f35d58034ef22d300852fa15ab818b3 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 15:13:12 -0500 Subject: [PATCH 57/68] Revise test function to improve readability --- tests/test_cache.py | 49 +++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index de7715c2f..f49d6ab11 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -10,36 +10,33 @@ def test_cache_save(): def get_cache_fnames_ref(): - cache._clear() + cache.clear() cache._enable() stump(np.random.rand(10), 3) - cache_data_fnames = [ - fname for fname in cache._get_cache() if fname.endswith(".nbc") - ] - cache_index_fnames = [ - fname for fname in cache._get_cache() if fname.endswith(".nbi") - ] - cache._clear() - return cache_data_fnames, cache_index_fnames + cache_files = cache._get_cache() + cache.clear() + return cache_files def get_cache_fnames_comp(): - cache._clear() - cache._save() + cache.clear() + cache.save() stump(np.random.rand(10), 3) - cache_data_fnames = [ - fname for fname in cache._get_cache() if fname.endswith(".nbc") - ] - cache_index_fnames = [ - fname for fname in cache._get_cache() if fname.endswith(".nbi") - ] - cache._clear() - return cache_data_fnames, cache_index_fnames + cache_files = cache._get_cache() + cache.clear() + return cache_files - ref_data, ref_index = get_cache_fnames_ref() - comp_data, comp_index = get_cache_fnames_comp() + ref_cache_files = get_cache_fnames_ref() + comp_cache_files = get_cache_fnames_comp() - assert sorted(ref_data) == sorted(comp_data) - assert set(ref_index).issubset(comp_index) + # check nbc files + ref_nbc = [fname for fname in ref_cache_files if fname.endswith(".nbc")] + comp_nbc = [fname for fname in comp_cache_files if fname.endswith(".nbc")] + assert sorted(ref_nbc) == sorted(comp_nbc) + + # check nbi files + ref_nbi = [fname for fname in ref_cache_files if fname.endswith(".nbi")] + comp_nbi = [fname for fname in comp_cache_files if fname.endswith(".nbi")] + assert set(ref_nbi).issubset(comp_nbi) def test_cache_save_after_clear(): @@ -47,14 +44,14 @@ def test_cache_save_after_clear(): m = 3 stump(T, m) - cache._save() + cache.save() ref_cache = cache._get_cache() - cache._clear() + cache.clear() # testing cache._clear() assert len(cache._get_cache()) == 0 - cache._save() + cache.save() comp_cache = cache._get_cache() # testing cache._save() after cache._clear() From 02115b2dd7a3463080e1ed21ade26668c7126faa Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 16:08:53 -0500 Subject: [PATCH 58/68] Add test function for fastmath --- stumpy/fastmath.py | 28 ++++++++++++++++++++++++++++ tests/test_fastmath.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/test_fastmath.py diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index e2d6f8ce7..b4a7d0e1a 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -1,8 +1,36 @@ import importlib +from numba import njit + from stumpy import config +@njit(fastmath=True) +def _add_assoc(x, y): # pragma: no cover + """ + A dummy function to test the fastmath module + + Parameters + ---------- + x : float + A float value + + y : floatf + A float value + + Returns + ------- + out : float + The ouput valus + + Notes + ----- + This is taken from the following link: + https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + """ + return (x - y) + y + + def _set(module_name, func_name, flag): """ Set fastmath flag for a given function diff --git a/tests/test_fastmath.py b/tests/test_fastmath.py new file mode 100644 index 000000000..3ab3ba1f6 --- /dev/null +++ b/tests/test_fastmath.py @@ -0,0 +1,37 @@ +import numpy as np + +from stumpy import fastmath + + +def test_fastmath(): + # Test the _set and _reset function in fastmath.py + # The test is done by changing the value of fastmath flag for + # the fastmath._add_assoc function + # See: https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + + x, y = 0.0, np.inf + + # fastmath=False + fastmath._set("fastmath", "_add_assoc", False) + out = fastmath._add_assoc(x, y) + assert np.isnan(out) + + # fastmath={'reassoc', 'nsz'} + fastmath._set("fastmath", "_add_assoc", {"reassoc", "nsz"}) + out = fastmath._add_assoc(x, y) + assert out == 0.0 + + # fastmath={'reassoc'} + fastmath._set("fastmath", "_add_assoc", {"reassoc"}) + out = fastmath._add_assoc(x, y) + assert np.isnan(out) + + # fastmath={'nsz'} + fastmath._set("fastmath", "_add_assoc", {"nsz"}) + out = fastmath._add_assoc(x, y) + assert np.isnan(out) + + # reset value of fastmath (default is True) + fastmath._reset("fastmath", "_add_assoc") + out = fastmath._add_assoc(x, y) + assert out == 0.0 From ecaead2f2c01eccc3e4bb2672e4f972819550d04 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 16:48:01 -0500 Subject: [PATCH 59/68] Revised test functions --- tests/test_fastmath.py | 47 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/tests/test_fastmath.py b/tests/test_fastmath.py index 3ab3ba1f6..cdd131d29 100644 --- a/tests/test_fastmath.py +++ b/tests/test_fastmath.py @@ -1,37 +1,36 @@ import numpy as np +from numba import njit from stumpy import fastmath -def test_fastmath(): +def test_set(): # Test the _set and _reset function in fastmath.py # The test is done by changing the value of fastmath flag for - # the fastmath._add_assoc function - # See: https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + # the fastmath._add_assoc function, taken from the following link: + # https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + py_func = fastmath._add_assoc.py_func - x, y = 0.0, np.inf + x = 0.0 + y = np.inf + fastmath_flags = [False, {"reassoc", "nsz"}, {"reassoc"}, {"nsz"}] + for flag in fastmath_flags: + ref = njit(fastmath=flag)(py_func)(x, y) - # fastmath=False - fastmath._set("fastmath", "_add_assoc", False) - out = fastmath._add_assoc(x, y) - assert np.isnan(out) - - # fastmath={'reassoc', 'nsz'} - fastmath._set("fastmath", "_add_assoc", {"reassoc", "nsz"}) - out = fastmath._add_assoc(x, y) - assert out == 0.0 + fastmath._set("fastmath", "_add_assoc", flag) + comp = fastmath._add_assoc(x, y) - # fastmath={'reassoc'} - fastmath._set("fastmath", "_add_assoc", {"reassoc"}) - out = fastmath._add_assoc(x, y) - assert np.isnan(out) + if np.isnan(ref) and np.isnan(comp): + assert True + else: + assert ref == comp - # fastmath={'nsz'} - fastmath._set("fastmath", "_add_assoc", {"nsz"}) - out = fastmath._add_assoc(x, y) - assert np.isnan(out) - # reset value of fastmath (default is True) +def test_reset(): + # Test the _set and _reset function in fastmath.py + # The test is done by changing the value of fastmath flag for + # the fastmath._add_assoc function, taken from the following link: + # https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + fastmath._set("fastmath", "_add_assoc", False) fastmath._reset("fastmath", "_add_assoc") - out = fastmath._add_assoc(x, y) - assert out == 0.0 + assert fastmath._add_assoc(0.0, np.inf) == 0.0 From 5c1a7a7aed2e02a38ec329eeb61c650dcabfb846 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 17:04:44 -0500 Subject: [PATCH 60/68] skip test if numba JIT is disabled --- tests/test_fastmath.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_fastmath.py b/tests/test_fastmath.py index cdd131d29..a9cb07ba8 100644 --- a/tests/test_fastmath.py +++ b/tests/test_fastmath.py @@ -1,8 +1,13 @@ +import numba import numpy as np +import pytest from numba import njit from stumpy import fastmath +if numba.config.DISABLE_JIT: + pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True) + def test_set(): # Test the _set and _reset function in fastmath.py From 89db05c84277b1fe62e6e5867cd4ad1031fa4a4e Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 18:42:52 -0500 Subject: [PATCH 61/68] omit test functions that require NUMBA JIT --- test.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 0136e16f5..64e7c83d5 100755 --- a/test.sh +++ b/test.sh @@ -152,15 +152,17 @@ set_ray_coveragerc() show_coverage_report() { + files_to_omit="fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py" set_ray_coveragerc - coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py $fcoveragerc + coverage report -m --fail-under=100 --skip-covered --omit=$files_to_omit $fcoveragerc } gen_coverage_xml_report() { # This function saves the coverage report in Cobertura XML format, which is compatible with codecov + files_to_omit="fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py" set_ray_coveragerc - coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py $fcoveragerc + coverage xml -o $fcoveragexml --fail-under=100 --omit=$files_to_omit $fcoveragerc } test_custom() From 7e72a7f53cfc4ef8a87ae9f579634c80abaeacdc Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 20:52:47 -0500 Subject: [PATCH 62/68] Removed the trivial test function --- tests/test_cache.py | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/tests/test_cache.py b/tests/test_cache.py index f49d6ab11..655ca49b4 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -8,37 +8,6 @@ pytest.skip("Skipping Tests JIT is disabled", allow_module_level=True) -def test_cache_save(): - def get_cache_fnames_ref(): - cache.clear() - cache._enable() - stump(np.random.rand(10), 3) - cache_files = cache._get_cache() - cache.clear() - return cache_files - - def get_cache_fnames_comp(): - cache.clear() - cache.save() - stump(np.random.rand(10), 3) - cache_files = cache._get_cache() - cache.clear() - return cache_files - - ref_cache_files = get_cache_fnames_ref() - comp_cache_files = get_cache_fnames_comp() - - # check nbc files - ref_nbc = [fname for fname in ref_cache_files if fname.endswith(".nbc")] - comp_nbc = [fname for fname in comp_cache_files if fname.endswith(".nbc")] - assert sorted(ref_nbc) == sorted(comp_nbc) - - # check nbi files - ref_nbi = [fname for fname in ref_cache_files if fname.endswith(".nbi")] - comp_nbi = [fname for fname in comp_cache_files if fname.endswith(".nbi")] - assert set(ref_nbi).issubset(comp_nbi) - - def test_cache_save_after_clear(): T = np.random.rand(10) m = 3 From b82b3c9a5f995fafcd82631979006c01a5ae5fb3 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Sun, 19 Jan 2025 20:57:17 -0500 Subject: [PATCH 63/68] Raise warning instead of error to avoid interrupting the program --- stumpy/cache.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stumpy/cache.py b/stumpy/cache.py index e8be7b1de..a08f00b36 100644 --- a/stumpy/cache.py +++ b/stumpy/cache.py @@ -204,10 +204,10 @@ def save(): None """ if numba.config.DISABLE_JIT: - msg = "Cannot save cache because NUMBA JIT is disabled" - raise OSError(msg) - - warnings.warn(CACHE_WARNING) - _save() + msg = "Could not save/cache function because NUMBA JIT is disabled" + warnings.warn(msg) + else: + warnings.warn(CACHE_WARNING) + _save() return From 9a695939b2a6be9c000dbc1ecd14f89a11c4f630 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Mon, 20 Jan 2025 22:49:51 -0500 Subject: [PATCH 64/68] improve readability --- tests/test_fastmath.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/test_fastmath.py b/tests/test_fastmath.py index a9cb07ba8..b80e0c78a 100644 --- a/tests/test_fastmath.py +++ b/tests/test_fastmath.py @@ -1,7 +1,6 @@ import numba import numpy as np import pytest -from numba import njit from stumpy import fastmath @@ -10,32 +9,36 @@ def test_set(): - # Test the _set and _reset function in fastmath.py # The test is done by changing the value of fastmath flag for # the fastmath._add_assoc function, taken from the following link: # https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath - py_func = fastmath._add_assoc.py_func - x = 0.0 - y = np.inf - fastmath_flags = [False, {"reassoc", "nsz"}, {"reassoc"}, {"nsz"}] - for flag in fastmath_flags: - ref = njit(fastmath=flag)(py_func)(x, y) + # case1: flag=False + fastmath._set("fastmath", "_add_assoc", flag=False) + out = fastmath._add_assoc(0, np.inf) + assert np.isnan(out) - fastmath._set("fastmath", "_add_assoc", flag) - comp = fastmath._add_assoc(x, y) + # case2: flag={'reassoc', 'nsz'} + fastmath._set("fastmath", "_add_assoc", flag={"reassoc", "nsz"}) + out = fastmath._add_assoc(0, np.inf) + assert out == 0.0 - if np.isnan(ref) and np.isnan(comp): - assert True - else: - assert ref == comp + # case3: flag={'reassoc'} + fastmath._set("fastmath", "_add_assoc", flag={"reassoc"}) + out = fastmath._add_assoc(0, np.inf) + assert np.isnan(out) + + # case4: flag={'nsz'} + fastmath._set("fastmath", "_add_assoc", flag={"nsz"}) + out = fastmath._add_assoc(0, np.inf) + assert np.isnan(out) def test_reset(): - # Test the _set and _reset function in fastmath.py # The test is done by changing the value of fastmath flag for # the fastmath._add_assoc function, taken from the following link: # https://numba.pydata.org/numba-doc/dev/user/performance-tips.html#fastmath + # and then reset it to the default value, i.e. `True` fastmath._set("fastmath", "_add_assoc", False) fastmath._reset("fastmath", "_add_assoc") assert fastmath._add_assoc(0.0, np.inf) == 0.0 From 7e5985d1bceaf236985fa052c0e1f123e0f77850 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Mon, 20 Jan 2025 23:23:05 -0500 Subject: [PATCH 65/68] remove intermediate variable --- test.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test.sh b/test.sh index 64e7c83d5..30e21b33d 100755 --- a/test.sh +++ b/test.sh @@ -152,17 +152,15 @@ set_ray_coveragerc() show_coverage_report() { - files_to_omit="fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py" set_ray_coveragerc - coverage report -m --fail-under=100 --skip-covered --omit=$files_to_omit $fcoveragerc + coverage report -m --fail-under=100 --skip-covered --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py $fcoveragerc } gen_coverage_xml_report() { # This function saves the coverage report in Cobertura XML format, which is compatible with codecov - files_to_omit="fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py" set_ray_coveragerc - coverage xml -o $fcoveragexml --fail-under=100 --omit=$files_to_omit $fcoveragerc + coverage xml -o $fcoveragexml --fail-under=100 --omit=fastmath.py,docstring.py,min_versions.py,ray_python_version.py,stumpy/cache.py,tests/test_cache.py,tests/test_fastmath.py $fcoveragerc } test_custom() From 2369e3376f480705391a0600171e2179f795abf8 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Tue, 21 Jan 2025 09:29:25 -0500 Subject: [PATCH 66/68] minor fixes --- stumpy/fastmath.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index b4a7d0e1a..94c34aa3e 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -2,7 +2,7 @@ from numba import njit -from stumpy import config +from . import config @njit(fastmath=True) @@ -39,8 +39,10 @@ def _set(module_name, func_name, flag): ---------- module_name : str The module name + func_name : str The function name + flag : set or bool The fastmath flag @@ -64,6 +66,7 @@ def _reset(module_name, func_name): ---------- module_name : str The module name + func_name : str The function name From 04eac83f5c10b238ec9fa33586c0e11c2153b317 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 22 Jan 2025 22:10:51 -0500 Subject: [PATCH 67/68] Add shell script code to check for harcoded fastmath flags --- stumpy/fastmath.py | 2 +- test.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/stumpy/fastmath.py b/stumpy/fastmath.py index 94c34aa3e..4e124026e 100644 --- a/stumpy/fastmath.py +++ b/stumpy/fastmath.py @@ -5,7 +5,7 @@ from . import config -@njit(fastmath=True) +@njit(fastmath=config.STUMPY_FASTMATH_TRUE) def _add_assoc(x, y): # pragma: no cover """ A dummy function to test the fastmath module diff --git a/test.sh b/test.sh index 30e21b33d..39765a494 100755 --- a/test.sh +++ b/test.sh @@ -98,6 +98,13 @@ check_fastmath() echo "Checking Missing fastmath flags in njit functions" ./fastmath.py --check stumpy check_errs $? + + echo "Checking hardcoded fastmath flags in njit functions" + if [[ $(grep -n fastmath= stumpy/*py | grep -vE 'fastmath=config' | wc -l) -gt "0" ]]; then + grep -n fastmath= stumpy/*py | grep -vE 'fastmath=config' + echo "Found one or more \`@njit()\` functions with a hardcoded \`fastmath\` flag." + exit 1 + fi } check_naive() From f5186a2cddbbc8a39d6ba7a16b82b9380b583655 Mon Sep 17 00:00:00 2001 From: NimaSarajpoor Date: Wed, 22 Jan 2025 22:18:08 -0500 Subject: [PATCH 68/68] minor fix on indention --- fastmath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastmath.py b/fastmath.py index b6fea39af..fe7dc0b56 100755 --- a/fastmath.py +++ b/fastmath.py @@ -13,7 +13,7 @@ def get_njit_funcs(pkg_dir): Parameters ---------- pkg_dir : str - The path to the directory containing some .py files + The path to the directory containing some .py files Returns -------