def test_view_as_blocks_3D_array(): A = np.arange(4 * 4 * 6).reshape(4, 4, 6) B = view_as_blocks(A, (1, 2, 2)) assert_equal(B.shape, (4, 2, 3, 1, 2, 2)) assert_equal(B[2:, 0, 2], np.array([[[[52, 53], [58, 59]]], [[[76, 77], [82, 83]]]]))
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]])) assert_equal(B[1, 0, 1, 1], 13)
def test_view_as_blocks_1D_array(): A = np.arange(10) B = view_as_blocks(A, (5, )) assert_equal(B, np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]))
def test_view_as_blocks_1D_array_wrong_block_shape(): A = np.arange(10) view_as_blocks(A, (3, ))
def test_view_as_blocks_wrong_block_dimension(): A = np.arange(10) view_as_blocks(A, (2, 2))
def test_view_as_blocks_block_too_large(): A = np.arange(10) view_as_blocks(A, (11, ))
def test_view_as_blocks_negative_shape(): A = np.arange(10) view_as_blocks(A, (-2, ))
def test_view_as_blocks_block_not_a_tuple(): A = np.arange(10) view_as_blocks(A, [5])
def test_view_as_blocks_1D_array(): A = np.arange(10) B = view_as_blocks(A, (5,)) assert_equal(B, np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]))
def test_view_as_blocks_1D_array_wrong_block_shape(): A = np.arange(10) view_as_blocks(A, (3,))
def test_view_as_blocks_block_too_large(): A = np.arange(10) view_as_blocks(A, (11,))
def test_view_as_blocks_negative_shape(): A = np.arange(10) view_as_blocks(A, (-2,))