|
18 | 18 | from gluonts.ev import Mean, Sum
|
19 | 19 | from gluonts.itertools import power_set
|
20 | 20 |
|
21 |
| -VALUE_STREAM = [ |
22 |
| - [ |
23 |
| - np.full((3, 5), np.nan), |
24 |
| - np.full((3, 5), np.nan), |
25 |
| - np.full((3, 5), np.nan), |
26 |
| - ], |
27 |
| - [ |
28 |
| - np.array([[0, np.nan], [0, 0]]), |
29 |
| - np.array([[0, 5], [-5, np.nan]]), |
30 |
| - ], |
31 |
| - [ |
32 |
| - np.full(shape=(3, 3), fill_value=1), |
33 |
| - np.full(shape=(1, 3), fill_value=4), |
34 |
| - ], |
35 |
| -] |
36 |
| - |
37 |
| -SUM_RES_AXIS_NONE = [ |
38 |
| - 0, |
39 |
| - 0, |
40 |
| - 21, |
41 |
| -] |
42 |
| - |
43 |
| -SUM_RES_AXIS_0 = [ |
44 |
| - np.zeros(5), |
45 |
| - np.array([-5, 5]), |
46 |
| - np.array([7, 7, 7]), |
47 |
| -] |
48 |
| -SUM_RES_AXIS_1 = [ |
49 |
| - np.zeros(9), |
50 |
| - np.array([0, 0, 5, -5]), |
51 |
| - np.array([3, 3, 3, 12]), |
52 |
| -] |
53 |
| - |
54 |
| - |
55 |
| -MEAN_RES_AXIS_NONE = [ |
56 |
| - np.nan, |
57 |
| - 0, |
58 |
| - 1.75, |
59 |
| -] |
60 |
| - |
61 |
| -MEAN_RES_AXIS_0 = [ |
62 |
| - np.full(5, np.nan), |
63 |
| - np.array([-1.25, 2.5]), |
64 |
| - np.array([1.75, 1.75, 1.75]), |
65 |
| -] |
66 |
| -MEAN_RES_AXIS_1 = [ |
67 |
| - np.full(9, np.nan), |
68 |
| - np.array([0, 0, 2.5, -5]), |
69 |
| - np.array([1, 1, 1, 4]), |
70 |
| -] |
71 |
| - |
72 | 21 |
|
73 | 22 | @pytest.mark.parametrize(
|
74 | 23 | "value_stream, res_axis_none, res_axis_0, res_axis_1",
|
75 |
| - zip(VALUE_STREAM, SUM_RES_AXIS_NONE, SUM_RES_AXIS_0, SUM_RES_AXIS_1), |
| 24 | + [ |
| 25 | + ( |
| 26 | + [ |
| 27 | + np.full((3, 5), 0.0), |
| 28 | + np.full((3, 5), 0.0), |
| 29 | + np.full((3, 5), 0.0), |
| 30 | + ], |
| 31 | + 0.0, |
| 32 | + np.zeros(5), |
| 33 | + np.zeros(9), |
| 34 | + ), |
| 35 | + ( |
| 36 | + np.ma.masked_invalid( |
| 37 | + [ |
| 38 | + np.full((3, 5), np.nan), |
| 39 | + np.full((3, 5), np.nan), |
| 40 | + np.full((3, 5), np.nan), |
| 41 | + ] |
| 42 | + ), |
| 43 | + 0, |
| 44 | + np.zeros(5), |
| 45 | + np.zeros(9), |
| 46 | + ), |
| 47 | + ( |
| 48 | + np.ma.masked_invalid( |
| 49 | + [ |
| 50 | + np.array([[0, np.nan], [0, 0]]), |
| 51 | + np.array([[0, 5], [-5, np.nan]]), |
| 52 | + ] |
| 53 | + ), |
| 54 | + 0, |
| 55 | + np.array([-5, 5]), |
| 56 | + np.array([0, 0, 5, -5]), |
| 57 | + ), |
| 58 | + ( |
| 59 | + [ |
| 60 | + np.full(shape=(3, 3), fill_value=1), |
| 61 | + np.full(shape=(1, 3), fill_value=4), |
| 62 | + ], |
| 63 | + 21, |
| 64 | + np.array([7, 7, 7]), |
| 65 | + np.array([3, 3, 3, 12]), |
| 66 | + ), |
| 67 | + ], |
76 | 68 | )
|
77 | 69 | def test_Sum(value_stream, res_axis_none, res_axis_0, res_axis_1):
|
78 | 70 | for axis, expected_result in zip(
|
79 | 71 | [None, 0, 1], [res_axis_none, res_axis_0, res_axis_1]
|
80 | 72 | ):
|
81 | 73 | sum = Sum(axis=axis)
|
82 | 74 | for values in value_stream:
|
83 |
| - sum.step(np.ma.masked_invalid(values)) |
| 75 | + sum.step(values) |
84 | 76 |
|
85 | 77 | np.testing.assert_almost_equal(sum.get(), expected_result)
|
86 | 78 |
|
87 | 79 |
|
88 | 80 | @pytest.mark.parametrize(
|
89 | 81 | "value_stream, res_axis_none, res_axis_0, res_axis_1",
|
90 |
| - zip(VALUE_STREAM, MEAN_RES_AXIS_NONE, MEAN_RES_AXIS_0, MEAN_RES_AXIS_1), |
| 82 | + [ |
| 83 | + ( |
| 84 | + [ |
| 85 | + np.full((3, 5), 0.0), |
| 86 | + np.full((3, 5), 0.0), |
| 87 | + np.full((3, 5), 0.0), |
| 88 | + ], |
| 89 | + 0.0, |
| 90 | + np.zeros(5), |
| 91 | + np.zeros(9), |
| 92 | + ), |
| 93 | + ( |
| 94 | + np.ma.masked_invalid( |
| 95 | + [ |
| 96 | + np.full((3, 5), np.nan), |
| 97 | + np.full((3, 5), np.nan), |
| 98 | + np.full((3, 5), np.nan), |
| 99 | + ] |
| 100 | + ), |
| 101 | + np.nan, |
| 102 | + np.full(5, np.nan), |
| 103 | + np.full(9, np.nan), |
| 104 | + ), |
| 105 | + ( |
| 106 | + np.ma.masked_invalid( |
| 107 | + [ |
| 108 | + np.array([[0, np.nan], [0, 0]]), |
| 109 | + np.array([[0, 5], [-5, np.nan]]), |
| 110 | + ] |
| 111 | + ), |
| 112 | + 0, |
| 113 | + np.array([-1.25, 2.5]), |
| 114 | + np.array([0, 0, 2.5, -5]), |
| 115 | + ), |
| 116 | + ( |
| 117 | + [ |
| 118 | + np.full(shape=(3, 3), fill_value=1), |
| 119 | + np.full(shape=(1, 3), fill_value=4), |
| 120 | + ], |
| 121 | + 1.75, |
| 122 | + np.array([1.75, 1.75, 1.75]), |
| 123 | + np.array([1, 1, 1, 4]), |
| 124 | + ), |
| 125 | + ], |
91 | 126 | )
|
92 | 127 | def test_Mean(value_stream, res_axis_none, res_axis_0, res_axis_1):
|
93 | 128 | for axis, expected_result in zip(
|
94 | 129 | [None, 0, 1], [res_axis_none, res_axis_0, res_axis_1]
|
95 | 130 | ):
|
96 | 131 | mean = Mean(axis=axis)
|
97 | 132 | for values in value_stream:
|
98 |
| - mean.step(np.ma.masked_invalid(values)) |
| 133 | + mean.step(values) |
99 | 134 |
|
100 | 135 | np.testing.assert_almost_equal(mean.get(), expected_result)
|
101 | 136 |
|
|
0 commit comments