Commit c0c68d8a authored by Mark Florisson's avatar Mark Florisson

Test broadcasting with object memoryviews

parent ca91ec9b
...@@ -1725,14 +1725,28 @@ def test_object_indices(): ...@@ -1725,14 +1725,28 @@ def test_object_indices():
for j in range(3): for j in range(3):
print myslice[j] print myslice[j]
cdef fused slice_1d:
object
int[:]
cdef fused slice_2d:
object
int[:, :]
@testcase @testcase
def test_ellipsis_expr(): def test_ellipsis_expr():
""" """
>>> test_ellipsis_expr() >>> test_ellipsis_expr()
8 8
8
""" """
cdef int[10] a cdef int[10] a
cdef int[:] m = a cdef int[:] m = a
_test_ellipsis_expr(m)
_test_ellipsis_expr(<object> m)
cdef _test_ellipsis_expr(slice_1d m):
m[4] = 8 m[4] = 8
m[...] = m[...] m[...] = m[...]
print m[4] print m[4]
...@@ -1752,6 +1766,12 @@ def test_slice_assignment(): ...@@ -1752,6 +1766,12 @@ def test_slice_assignment():
cdef int[:, :] m = carray cdef int[:, :] m = carray
cdef int[:, :] copy = m[-6:-1, 60:65].copy() cdef int[:, :] copy = m[-6:-1, 60:65].copy()
_test_slice_assignment(m, copy)
_test_slice_assignment(<object> m, <object> copy)
cdef _test_slice_assignment(slice_2d m, slice_2d copy):
cdef int i, j
m[...] = m[::-1, ::-1] m[...] = m[::-1, ::-1]
m[:, :] = m[::-1, ::-1] m[:, :] = m[::-1, ::-1]
m[-5:, -5:] = m[-6:-1, 60:65] m[-5:, -5:] = m[-6:-1, 60:65]
...@@ -1775,12 +1795,22 @@ def test_slice_assignment_broadcast_leading(): ...@@ -1775,12 +1795,22 @@ def test_slice_assignment_broadcast_leading():
cdef int[:, :] a = array1 cdef int[:, :] a = array1
cdef int[:] b = array2 cdef int[:] b = array2
_test_slice_assignment_broadcast_leading(a, b)
for i in range(10):
array1[0][i] = i
_test_slice_assignment_broadcast_leading(<object> a, <object> b)
cdef _test_slice_assignment_broadcast_leading(slice_2d a, slice_1d b):
cdef int i
b[:] = a[:, :] b[:] = a[:, :]
b = b[::-1] b = b[::-1]
a[:, :] = b[:] a[:, :] = b[:]
for i in range(10): for i in range(10):
assert a[0, i] == b[i] == 10 - 1 - i, (b[i], a[0, i]) assert a[0, i] == b[i] == 10 - 1 - i, (a[0, i], b[i], 10 - 1 - i)
@testcase @testcase
def test_slice_assignment_broadcast_strides(): def test_slice_assignment_broadcast_strides():
...@@ -1798,6 +1828,12 @@ def test_slice_assignment_broadcast_strides(): ...@@ -1798,6 +1828,12 @@ def test_slice_assignment_broadcast_strides():
cdef int[:, :] dst = dst_array cdef int[:, :] dst = dst_array
cdef int[:, :] dst_f = dst.copy_fortran() cdef int[:, :] dst_f = dst.copy_fortran()
_test_slice_assignment_broadcast_strides(src, dst, dst_f)
_test_slice_assignment_broadcast_strides(<object> src, <object> dst, <object> dst_f)
cdef _test_slice_assignment_broadcast_strides(slice_1d src, slice_2d dst, slice_2d dst_f):
cdef int i, j
dst[1:] = src[-1:-6:-1] dst[1:] = src[-1:-6:-1]
dst_f[1:] = src[-1:-6:-1] dst_f[1:] = src[-1:-6:-1]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment