Skip to content

Commit 10f4651

Browse files
committed
Add rare-case tests for snippets
1 parent 423c679 commit 10f4651

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

tests/test_snippets.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,105 @@ def test_mpdist_snippets_s_with_isconstant(T, m, k, s):
222222
)
223223
npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION)
224224
npt.assert_almost_equal(ref_regimes, cmp_regimes)
225+
226+
227+
def test_mpdist_snippets_s_with_isconstant_rare_case_1():
228+
# This test fails when the naive implementation of snippet,
229+
# i.e. `naive.mpdist_snippets`, uses `np.sum` instead of
230+
# math.fsum when calculating the sum of many small
231+
# floating point numbers. For more details, see issue #1061
232+
233+
seed = 1615
234+
np.random.seed(seed)
235+
T = np.random.uniform(-1000.0, 1000.0, 64)
236+
m = 10
237+
s = 3
238+
k = 3
239+
240+
isconstant_custom_func = functools.partial(
241+
naive.isconstant_func_stddev_threshold, quantile_threshold=0.05
242+
)
243+
(
244+
ref_snippets,
245+
ref_indices,
246+
ref_profiles,
247+
ref_fractions,
248+
ref_areas,
249+
ref_regimes,
250+
) = naive.mpdist_snippets(
251+
T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func
252+
)
253+
(
254+
cmp_snippets,
255+
cmp_indices,
256+
cmp_profiles,
257+
cmp_fractions,
258+
cmp_areas,
259+
cmp_regimes,
260+
) = snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func)
261+
262+
npt.assert_almost_equal(
263+
ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION
264+
)
265+
npt.assert_almost_equal(
266+
ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION
267+
)
268+
npt.assert_almost_equal(
269+
ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION
270+
)
271+
npt.assert_almost_equal(
272+
ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION
273+
)
274+
npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION)
275+
npt.assert_almost_equal(ref_regimes, cmp_regimes)
276+
277+
278+
def test_mpdist_snippets_s_with_isconstant_rare_case_2():
279+
# This test fails when the naive implementation of snippet,
280+
# i.e. `naive.mpdist_snippets`, uses `np.sum` instead of
281+
# math.fsum when calculating the sum of many small
282+
# floating point numbers. For more details, see issue #1061
283+
284+
seed = 2636
285+
np.random.seed(seed)
286+
T = np.random.uniform(-1000.0, 1000.0, 64)
287+
m = 9
288+
s = 3
289+
k = 3
290+
291+
isconstant_custom_func = functools.partial(
292+
naive.isconstant_func_stddev_threshold, quantile_threshold=0.05
293+
)
294+
(
295+
ref_snippets,
296+
ref_indices,
297+
ref_profiles,
298+
ref_fractions,
299+
ref_areas,
300+
ref_regimes,
301+
) = naive.mpdist_snippets(
302+
T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func
303+
)
304+
(
305+
cmp_snippets,
306+
cmp_indices,
307+
cmp_profiles,
308+
cmp_fractions,
309+
cmp_areas,
310+
cmp_regimes,
311+
) = snippets(T, m, k, s=s, mpdist_T_subseq_isconstant=isconstant_custom_func)
312+
313+
npt.assert_almost_equal(
314+
ref_snippets, cmp_snippets, decimal=config.STUMPY_TEST_PRECISION
315+
)
316+
npt.assert_almost_equal(
317+
ref_indices, cmp_indices, decimal=config.STUMPY_TEST_PRECISION
318+
)
319+
npt.assert_almost_equal(
320+
ref_profiles, cmp_profiles, decimal=config.STUMPY_TEST_PRECISION
321+
)
322+
npt.assert_almost_equal(
323+
ref_fractions, cmp_fractions, decimal=config.STUMPY_TEST_PRECISION
324+
)
325+
npt.assert_almost_equal(ref_areas, cmp_areas, decimal=config.STUMPY_TEST_PRECISION)
326+
npt.assert_almost_equal(ref_regimes, cmp_regimes)

0 commit comments

Comments
 (0)