def test_patch_iter_notcontiguous():
    img = np.asfortranarray(np.reshape(np.arange(12), (3, 4)))

    patches = list(ni.patch_iter(img, (2, 2), 2))
    expected = [np.array([[0, 1], [4, 5]]),
                np.array([[2, 3], [6, 7]])]
    for p, e in zip(patches, expected):
        nt.assert_allclose(p, e)
def test_patch_iter_3channel():
    img = np.reshape(np.arange(12 * 3), (3, 4, 3))

    patches = list(ni.patch_iter(img, (2, 2), 2))
    expected = [
        np.array([[[0, 1, 2], [3, 4, 5]], [[12, 13, 14], [15, 16, 17]]]),
        np.array([[[6, 7, 8], [9, 10, 11]], [[18, 19, 20], [21, 22, 23]]])]
    for p, e in zip(patches, expected):
        nt.assert_allclose(p, e)
def test_patch_iter():
    img = np.reshape(np.arange(12), (3, 4))

    patches = list(ni.patch_iter(img, (2, 2), 2))
    expected = [np.array([[0, 1], [4, 5]]),
                np.array([[2, 3], [6, 7]])]
    for p, e in zip(patches, expected):
        nt.assert_allclose(p, e)

    patches = list(ni.patch_iter(img, (2, 2), 3))
    expected = [np.array([[0, 1], [4, 5]])]
    for p, e in zip(patches, expected):
        nt.assert_allclose(p, e)

    patches = list(ni.patch_iter(img, (1, 3), 1))
    expected = [np.array([[0, 1, 2]]), np.array([[1, 2, 3]]),
                np.array([[4, 5, 6]]), np.array([[5, 6, 7]]),
                np.array([[8, 9, 10]]), np.array([[9, 10, 11]])]
    for p, e in zip(patches, expected):
        nt.assert_allclose(p, e)
def test_patch_iter_warning():
    with pytest.warns(UserWarning):
        img = np.asfortranarray(np.reshape(np.arange(12), (3, 4)))
        list(ni.patch_iter(img, (2, 2), 2))
        warn("Image is not contiguous and will be copied!", UserWarning)