Repository: TDAmeritrade/stumpy

Issue:
stumpy.match bug with parameters: Sliding mean and Sliding standard deviation
### Discussed in https://github.com/TDAmeritrade/stumpy/discussions/581

<div type='discussions-op-text'>

<sup>Originally posted by **brunopinos31** March 31, 2022</sup>
I have a bug when i try to use the stumpy.match function with parameters: Sliding mean and Sliding standard deviation.

![image](https://user-images.githubusercontent.com/92527271/161106075-5853222b-5073-4e57-8cda-e75d1abe171b.png)
</div>

Comments:

Patch:
diff --git a/stumpy/aamp_motifs.py b/stumpy/aamp_motifs.py
index 5fc6cb6..1e00c52 100644
--- a/stumpy/aamp_motifs.py
+++ b/stumpy/aamp_motifs.py
@@ -380,6 +380,8 @@ def aamp_match(
 
     if T_subseq_isfinite is None:
         T, T_subseq_isfinite = core.preprocess_non_normalized(T, m)
+    if len(T_subseq_isfinite.shape) == 1:
+        T_subseq_isfinite = T_subseq_isfinite[np.newaxis, :]
 
     D = np.empty((d, n - m + 1))
     for i in range(d):
diff --git a/stumpy/motifs.py b/stumpy/motifs.py
index 213002c..5b59b14 100644
--- a/stumpy/motifs.py
+++ b/stumpy/motifs.py
@@ -445,6 +445,10 @@ def match(
 
     if M_T is None or Σ_T is None:  # pragma: no cover
         T, M_T, Σ_T = core.preprocess(T, m)
+    if len(M_T.shape) == 1:
+        M_T = M_T[np.newaxis, :]
+    if len(Σ_T.shape) == 1:
+        Σ_T = Σ_T[np.newaxis, :]
 
     D = np.empty((d, n - m + 1))
     for i in range(d):


Test patch:
diff --git a/tests/test_aamp_motifs.py b/tests/test_aamp_motifs.py
index b8325f5..006521f 100644
--- a/tests/test_aamp_motifs.py
+++ b/tests/test_aamp_motifs.py
@@ -2,7 +2,7 @@ import numpy as np
 import numpy.testing as npt
 import pytest
 
-from stumpy import aamp_motifs, aamp_match
+from stumpy import core, aamp_motifs, aamp_match
 
 import naive
 
@@ -211,3 +211,31 @@ def test_aamp_match(Q, T):
         )
 
         npt.assert_almost_equal(left, right)
+
+
+@pytest.mark.parametrize("Q, T", test_data)
+def test_aamp_match_T_subseq_isfinite(Q, T):
+    m = Q.shape[0]
+    excl_zone = int(np.ceil(m / 4))
+    max_distance = 0.3
+    T, T_subseq_isfinite = core.preprocess_non_normalized(T, len(Q))
+
+    for p in [1.0, 2.0, 3.0]:
+        left = naive_aamp_match(
+            Q,
+            T,
+            p=p,
+            excl_zone=excl_zone,
+            max_distance=max_distance,
+        )
+
+        right = aamp_match(
+            Q,
+            T,
+            T_subseq_isfinite,
+            p=p,
+            max_matches=None,
+            max_distance=max_distance,
+        )
+
+        npt.assert_almost_equal(left, right)
diff --git a/tests/test_motifs.py b/tests/test_motifs.py
index 07dbf2c..beef44e 100644
--- a/tests/test_motifs.py
+++ b/tests/test_motifs.py
@@ -235,3 +235,30 @@ def test_match(Q, T):
     )
 
     npt.assert_almost_equal(left, right)
+
+
+@pytest.mark.parametrize("Q, T", test_data)
+def test_match_mean_stddev(Q, T):
+    m = Q.shape[0]
+    excl_zone = int(np.ceil(m / 4))
+    max_distance = 0.3
+
+    left = naive_match(
+        Q,
+        T,
+        excl_zone,
+        max_distance=max_distance,
+    )
+
+    M_T, Σ_T = core.compute_mean_std(T, len(Q))
+
+    right = match(
+        Q,
+        T,
+        M_T,
+        Σ_T,
+        max_matches=None,
+        max_distance=lambda D: max_distance,  # also test lambda functionality
+    )
+
+    npt.assert_almost_equal(left, right)