3
3
import numpy as np
4
4
import pytest
5
5
6
- from matplotlib import mlab , _api
6
+ from matplotlib import mlab
7
7
8
8
9
9
class TestStride :
@@ -13,12 +13,7 @@ def get_base(self, x):
13
13
y = y .base
14
14
return y
15
15
16
- @pytest .fixture (autouse = True )
17
- def stride_is_deprecated (self ):
18
- with _api .suppress_matplotlib_deprecation_warning ():
19
- yield
20
-
21
- def calc_window_target (self , x , NFFT , noverlap = 0 , axis = 0 ):
16
+ def calc_window_target (self , x , NFFT , noverlap = 0 ):
22
17
"""
23
18
This is an adaptation of the original window extraction algorithm.
24
19
This is here to test to make sure the new implementation has the same
@@ -32,55 +27,43 @@ def calc_window_target(self, x, NFFT, noverlap=0, axis=0):
32
27
# do the ffts of the slices
33
28
for i in range (n ):
34
29
result [:, i ] = x [ind [i ]:ind [i ]+ NFFT ]
35
- if axis == 1 :
36
- result = result .T
37
30
return result
38
31
39
- @pytest .mark .parametrize ('shape' , [(), (10 , 1 )], ids = ['0D' , '2D' ])
40
- def test_stride_windows_invalid_input_shape (self , shape ):
41
- x = np .arange (np .prod (shape )).reshape (shape )
42
- with pytest .raises (ValueError ):
43
- mlab .stride_windows (x , 5 )
44
-
45
32
@pytest .mark .parametrize ('n, noverlap' ,
46
- [(0 , None ), (11 , None ), (2 , 2 ), (2 , 3 )],
47
- ids = ['n less than 1' , 'n greater than input' ,
48
- 'noverlap greater than n' ,
33
+ [(2 , 2 ), (2 , 3 )],
34
+ ids = ['noverlap greater than n' ,
49
35
'noverlap equal to n' ])
50
36
def test_stride_windows_invalid_params (self , n , noverlap ):
51
37
x = np .arange (10 )
52
38
with pytest .raises (ValueError ):
53
- mlab .stride_windows (x , n , noverlap )
39
+ mlab ._stride_windows (x , n , noverlap )
54
40
55
- @pytest .mark .parametrize ('axis' , [0 , 1 ], ids = ['axis0' , 'axis1' ])
56
41
@pytest .mark .parametrize ('n, noverlap' ,
57
42
[(1 , 0 ), (5 , 0 ), (15 , 2 ), (13 , - 3 )],
58
43
ids = ['n1-noverlap0' , 'n5-noverlap0' ,
59
44
'n15-noverlap2' , 'n13-noverlapn3' ])
60
- def test_stride_windows (self , n , noverlap , axis ):
45
+ def test_stride_windows (self , n , noverlap ):
61
46
x = np .arange (100 )
62
- y = mlab .stride_windows (x , n , noverlap = noverlap , axis = axis )
47
+ y = mlab ._stride_windows (x , n , noverlap = noverlap )
63
48
64
49
expected_shape = [0 , 0 ]
65
- expected_shape [axis ] = n
66
- expected_shape [1 - axis ] = 100 // (n - noverlap )
67
- yt = self .calc_window_target (x , n , noverlap = noverlap , axis = axis )
50
+ expected_shape [0 ] = n
51
+ expected_shape [1 ] = 100 // (n - noverlap )
52
+ yt = self .calc_window_target (x , n , noverlap = noverlap )
68
53
69
54
assert yt .shape == y .shape
70
55
assert_array_equal (yt , y )
71
56
assert tuple (expected_shape ) == y .shape
72
57
assert self .get_base (y ) is x
73
58
74
- @pytest .mark .parametrize ('axis' , [0 , 1 ], ids = ['axis0' , 'axis1' ])
75
- def test_stride_windows_n32_noverlap0_unflatten (self , axis ):
59
+ def test_stride_windows_n32_noverlap0_unflatten (self ):
76
60
n = 32
77
61
x = np .arange (n )[np .newaxis ]
78
62
x1 = np .tile (x , (21 , 1 ))
79
63
x2 = x1 .flatten ()
80
- y = mlab .stride_windows (x2 , n , axis = axis )
64
+ y = mlab ._stride_windows (x2 , n )
81
65
82
- if axis == 0 :
83
- x1 = x1 .T
66
+ x1 = x1 .T
84
67
assert y .shape == x1 .shape
85
68
assert_array_equal (y , x1 )
86
69
0 commit comments