Skip to content

Commit 268c78e

Browse files
committed
Fixed #1002 Added Named Multi-dimensional Matrix Profiles
1 parent d60fa39 commit 268c78e

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

stumpy/maamp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from numba import njit, prange
99

1010
from . import config, core
11+
from .mmparray import mparray
1112

1213

1314
def _multi_mass_absolute(Q, T, m, Q_subseq_isfinite, T_subseq_isfinite, p=2.0):
@@ -979,4 +980,4 @@ def maamp(T, m, include=None, discords=False, p=2.0):
979980
discords,
980981
)
981982

982-
return P, I
983+
return mparray(P_=P, I_=I)

stumpy/maamped.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from . import config, core
1010
from .maamp import _get_first_maamp_profile, _get_multi_p_norm, _maamp
11+
from .mmparray import mparray
1112

1213

1314
def _dask_maamped(
@@ -412,4 +413,4 @@ def maamped(client, T, m, include=None, discords=False, p=2.0):
412413
discords,
413414
)
414415

415-
return P, I
416+
return mparray(P_=P, I_=I)

stumpy/mmparray.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from collections import namedtuple
2+
3+
mparray = namedtuple("mparray", "P_,I_")

stumpy/mstump.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from . import config, core
1212
from .maamp import maamp, maamp_mdl, maamp_multi_distance_profile, maamp_subspace
13+
from .mmparray import mparray
1314

1415

1516
def _multi_mass(
@@ -1281,4 +1282,4 @@ def mstump(
12811282
discords,
12821283
)
12831284

1284-
return P, I
1285+
return mparray(P_=P, I_=I)

stumpy/mstumped.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from . import config, core
1010
from .maamped import maamped
11+
from .mmparray import mparray
1112
from .mstump import _get_first_mstump_profile, _get_multi_QT, _mstump
1213

1314

@@ -531,4 +532,4 @@ def mstumped(
531532
discords,
532533
)
533534

534-
return P, I
535+
return mparray(P_=P, I_=I)

test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ do
1919
test_mode="gpu"
2020
elif [[ $var == "show" ]]; then
2121
test_mode="show"
22+
elif [[ $var == "count" ]]; then
23+
test_mode="count"
2224
elif [[ $var == "custom" ]]; then
2325
test_mode="custom"
2426
elif [[ $var == "report" ]]; then
@@ -273,6 +275,12 @@ check_links()
273275
pytest --check-links docs/Tutorial_*.ipynb notebooks/Tutorial_*.ipynb docs/*.md docs/*.rst ./*.md ./*.rst
274276
}
275277

278+
count()
279+
{
280+
test_count=$(pytest --collect-only -q | sed '$d' | sed '$d' | wc -l | sed 's/ //g')
281+
echo "Found $test_count Unit Tests"
282+
}
283+
276284
clean_up()
277285
{
278286
echo "Cleaning Up"
@@ -340,6 +348,9 @@ elif [[ $test_mode == "report" ]]; then
340348
elif [[ $test_mode == "gpu" ]]; then
341349
echo "Executing GPU Unit Tests Only"
342350
test_gpu
351+
elif [[ $test_mode == "count" ]]; then
352+
echo "Counting Unit Tests"
353+
count
343354
elif [[ $test_mode == "links" ]]; then
344355
echo "Check Notebook Links Only"
345356
check_links

tests/test_mmparray.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import naive
2+
import numpy as np
3+
import numpy.testing as npt
4+
import pytest
5+
6+
from stumpy import maamp, mstump
7+
8+
test_data = [
9+
(np.array([[584, -11, 23, 79, 1001, 0, -19]], dtype=np.float64), 3),
10+
(np.random.uniform(-1000, 1000, [5, 20]).astype(np.float64), 5),
11+
]
12+
13+
14+
@pytest.mark.parametrize("T, m", test_data)
15+
def test_mmparray_mstump(T, m):
16+
excl_zone = int(np.ceil(m / 4))
17+
18+
ref_P, ref_I = naive.mstump(T, m, excl_zone)
19+
comp = mstump(T, m)
20+
21+
npt.assert_almost_equal(ref_P, comp.P_)
22+
npt.assert_almost_equal(ref_I, comp.I_)
23+
24+
25+
@pytest.mark.parametrize("T, m", test_data)
26+
def test_mmparray_maamp(T, m):
27+
excl_zone = int(np.ceil(m / 4))
28+
29+
for p in [1.0, 2.0, 3.0]:
30+
ref_P, ref_I = naive.maamp(T, m, excl_zone, p=p)
31+
comp = maamp(T, m, p=p)
32+
33+
npt.assert_almost_equal(ref_P, comp.P_)
34+
npt.assert_almost_equal(ref_I, comp.I_)

0 commit comments

Comments
 (0)