| 359 | @pytest.mark.parametrize("substitute", substitution_values) |
| 360 | @pytest.mark.parametrize("substitution_locations", substitution_locations) |
| 361 | def test_aamp_floss_inf_nan(substitute, substitution_locations): |
| 362 | T = np.random.uniform(-1000, 1000, [64]) |
| 363 | m = 5 |
| 364 | n = 30 |
| 365 | data = T.copy() |
| 366 | for substitution_location in substitution_locations: |
| 367 | data[:] = T[:] |
| 368 | data[substitution_location] = substitute |
| 369 | old_data = data[:n] |
| 370 | |
| 371 | mp = naive_right_mp(old_data, m, normalize=False) |
| 372 | comp_mp = aamp(old_data, m) |
| 373 | k = mp.shape[0] |
| 374 | |
| 375 | rolling_Ts = core.rolling_window(data[1:], n) |
| 376 | L = 5 |
| 377 | excl_factor = 1 |
| 378 | custom_iac = _iac(k, bidirectional=False) |
| 379 | stream = floss( |
| 380 | comp_mp, old_data, m, L, excl_factor, custom_iac=custom_iac, normalize=False |
| 381 | ) |
| 382 | last_idx = n - m + 1 |
| 383 | excl_zone = int(np.ceil(m / 4)) |
| 384 | zone_start = max(0, k - excl_zone) |
| 385 | for i, ref_T in enumerate(rolling_Ts): |
| 386 | mp[:, 1] = -1 |
| 387 | mp[:, 2] = -1 |
| 388 | mp[:] = np.roll(mp, -1, axis=0) |
| 389 | mp[-1, 0] = np.inf |
| 390 | mp[-1, 3] = last_idx + i |
| 391 | |
| 392 | D = naive.aamp_distance_profile(ref_T[-m:], ref_T, m) |
| 393 | D[zone_start:] = np.inf |
| 394 | |
| 395 | ref_T_isfinite = np.isfinite(ref_T) |
| 396 | ref_T_subseq_isfinite = np.all( |
| 397 | core.rolling_window(ref_T_isfinite, m), axis=1 |
| 398 | ) |
| 399 | |
| 400 | D[~ref_T_subseq_isfinite] = np.inf |
| 401 | update_idx = np.argwhere(D < mp[:, 0]).flatten() |
| 402 | mp[update_idx, 0] = D[update_idx] |
| 403 | mp[update_idx, 3] = last_idx + i |
| 404 | |
| 405 | ref_cac_1d = _cac( |
| 406 | mp[:, 3] - i - 1, |
| 407 | L, |
| 408 | bidirectional=False, |
| 409 | excl_factor=excl_factor, |
| 410 | custom_iac=custom_iac, |
| 411 | ) |
| 412 | |
| 413 | ref_mp = mp.copy() |
| 414 | ref_P = ref_mp[:, 0] |
| 415 | ref_I = ref_mp[:, 3] |
| 416 | ref_I[ref_mp[:, 0] == np.inf] = -1 |
| 417 | |
| 418 | stream.update(ref_T[-1]) |