Add support for non-unit step

This commit is contained in:
Tony S Yu
2013-10-21 23:02:51 -05:00
parent 6ce788a5d3
commit e794aed012
2 changed files with 8 additions and 9 deletions
-3
View File
@@ -38,9 +38,6 @@ def _verify_picture_index(index):
if isinstance(dim_slice, int):
index[i] = dim_slice = slice(dim_slice, dim_slice + 1)
if dim_slice.step is not None and dim_slice.step != 1:
raise IndexError("Only a step size of 1 is supported")
return tuple(index)
+8 -6
View File
@@ -205,6 +205,14 @@ def test_negative_slice():
assert pic[0, -3:] == pic[0, n - 3:]
def test_getitem_with_step():
h, w = 5, 5
array = _array_2d_to_RGB(np.linspace(0, 255, h * w).reshape(h, w))
pic = novice.Picture(array=array)
sliced_pic = pic[::2, ::2]
assert sliced_pic == novice.Picture(array=array[::2, ::2])
@raises(IndexError)
def test_1d_getitem_raises():
pic = novice.Picture.from_size((1, 1))
@@ -229,12 +237,6 @@ def test_3d_setitem_raises():
pic[1, 2, 3] = 0
@raises(IndexError)
def test_getitem_with_step_raises():
pic = novice.Picture.from_size((3, 3))
pic[::2, ::2]
@raises(IndexError)
def test_out_of_bounds_indexing():
pic = novice.open(SMALL_IMAGE_PATH)