Allow view_as_window to take a tuple step, and update tests

This commit is contained in:
Steven Silvester
2015-06-07 06:13:36 -05:00
parent da8e2c7c69
commit 3f8e94ff0c
2 changed files with 55 additions and 25 deletions
+28 -9
View File
@@ -47,7 +47,7 @@ def test_view_as_blocks_2D_array():
A = np.arange(4 * 4).reshape(4, 4)
B = view_as_blocks(A, (2, 2))
assert_equal(B[0, 1], np.array([[2, 3],
[6, 7]]))
[6, 7]]))
assert_equal(B[1, 0, 1, 1], 13)
@@ -67,12 +67,6 @@ def test_view_as_windows_input_not_array():
view_as_windows(A, (2,))
@raises(TypeError)
def test_view_as_windows_window_not_tuple():
A = np.arange(10)
view_as_windows(A, [2])
@raises(ValueError)
def test_view_as_windows_wrong_window_dimension():
A = np.arange(10)
@@ -96,6 +90,7 @@ def test_view_as_windows_step_below_one():
A = np.arange(10)
view_as_windows(A, (11,), step=0.9)
def test_view_as_windows_1D():
A = np.arange(10)
window_shape = (3,)
@@ -135,7 +130,7 @@ def test_view_as_windows_2D():
def test_view_as_windows_with_skip():
A = np.arange(20).reshape((5, 4))
B = view_as_windows(A, (2, 2), step=2)
B = view_as_windows(A, 2, step=2)
assert_equal(B, [[[[0, 1],
[4, 5]],
[[2, 3],
@@ -145,7 +140,7 @@ def test_view_as_windows_with_skip():
[[10, 11],
[14, 15]]]])
C = view_as_windows(A, (2, 2), step=4)
C = view_as_windows(A, 2, step=4)
assert_equal(C.shape, (1, 1, 2, 2))
@@ -157,5 +152,29 @@ def test_views_non_contiguous():
assert_warns(RuntimeWarning, view_as_windows, A, (2, 2))
def test_view_as_windows_step_tuple():
A = np.arange(24).reshape((6, 4))
B = view_as_windows(A, (3, 2), step=3)
assert B.shape == (2, 1, 3, 2)
assert B.size != A.size
C = view_as_windows(A, (3, 2), step=(3, 2))
assert C.shape == (2, 2, 3, 2)
assert C.size == A.size
assert_equal(C, [[[[0, 1],
[4, 5],
[8, 9]],
[[2, 3],
[6, 7],
[10, 11]]],
[[[12, 13],
[16, 17],
[20, 21]],
[[14, 15],
[18, 19],
[22, 23]]]])
if __name__ == '__main__':
np.testing.run_module_suite()