22from unittest .mock import patch
33
44import naive
5- import numba
65import numpy as np
76import numpy .testing as npt
87import pytest
98from numba import cuda
109
11- from stumpy import cache , config , core , fastmath , rng , sdp
10+ from stumpy import config , core , rng , sdp
1211
1312if cuda .is_available ():
1413 from stumpy .gpu_stump import gpu_stump
@@ -118,18 +117,19 @@ def test_calculate_squared_distance():
118117 npt .assert_almost_equal (ref , comp , decimal = 14 )
119118
120119
121- def test_snippets ():
120+ @pytest .mark .parametrize (
121+ "seed, m, k, s" , [(2135137202 , 10 , 3 , 3 ), (2636 , 9 , 3 , 3 ), (332 , 10 , 3 , 3 )]
122+ )
123+ def test_snippets (seed , m , k , s ):
122124 # This test function raises an error if there is a considerable loss of precision
123125 # that violates the symmetry property of a distance measure.
124- m = 10
125- k = 3
126- s = 3
127- with rng .fix_seed (332 ):
128- T = rng .RNG .uniform (- 1000.0 , 1000.0 , [64 ])
126+ with rng .fix_seed (seed ):
127+ T = rng .RNG .uniform (- 1000 , 1000 , [64 ]).astype (np .float64 )
129128
130129 isconstant_custom_func = functools .partial (
131130 naive .isconstant_func_stddev_threshold , quantile_threshold = 0.05
132131 )
132+
133133 (
134134 ref_snippets ,
135135 ref_indices ,
@@ -138,9 +138,12 @@ def test_snippets():
138138 ref_areas ,
139139 ref_regimes ,
140140 ) = naive .mpdist_snippets (
141- T , m , k , s = s , mpdist_T_subseq_isconstant = isconstant_custom_func
141+ T ,
142+ m ,
143+ k ,
144+ s = s ,
145+ mpdist_T_subseq_isconstant = isconstant_custom_func ,
142146 )
143-
144147 (
145148 cmp_snippets ,
146149 cmp_indices ,
@@ -150,29 +153,6 @@ def test_snippets():
150153 cmp_regimes ,
151154 ) = snippets (T , m , k , s = s , mpdist_T_subseq_isconstant = isconstant_custom_func )
152155
153- if (
154- not np .allclose (ref_snippets , cmp_snippets ) and not numba .config .DISABLE_JIT
155- ): # pragma: no cover
156- # Revise fastmath flags by removing reassoc (to improve precision),
157- # recompile njit functions, and re-compute snippets.
158- fastmath ._set (
159- "core" ,
160- "_calculate_squared_distance" ,
161- {"nsz" , "arcp" , "contract" , "afn" },
162- )
163- cache ._recompile ()
164-
165- (
166- cmp_snippets ,
167- cmp_indices ,
168- cmp_profiles ,
169- cmp_fractions ,
170- cmp_areas ,
171- cmp_regimes ,
172- ) = snippets (
173- T , m , k , s = s , mpdist_T_subseq_isconstant = isconstant_custom_func
174- )
175-
176156 npt .assert_almost_equal (
177157 ref_snippets , cmp_snippets , decimal = config .STUMPY_TEST_PRECISION
178158 )
@@ -190,11 +170,6 @@ def test_snippets():
190170 )
191171 npt .assert_almost_equal (ref_regimes , cmp_regimes )
192172
193- if not numba .config .DISABLE_JIT : # pragma: no cover
194- # Revert fastmath flag back to their default values
195- fastmath ._reset ("core" , "_calculate_squared_distance" )
196- cache ._recompile ()
197-
198173
199174@pytest .mark .filterwarnings ("ignore" , category = NumbaPerformanceWarning )
200175@patch ("stumpy.config.STUMPY_THREADS_PER_BLOCK" , TEST_THREADS_PER_BLOCK )
0 commit comments