Commit 00cf5cd5 authored by Mark Florisson's avatar Mark Florisson

Fix cython.view.array cast step error

parent 37d13c94
...@@ -7336,6 +7336,7 @@ class CythonArrayNode(ExprNode): ...@@ -7336,6 +7336,7 @@ class CythonArrayNode(ExprNode):
first_or_last = axis_no in (0, ndim - 1) first_or_last = axis_no in (0, ndim - 1)
if not axis.step.is_none and first_or_last: if not axis.step.is_none and first_or_last:
# '1' in the first or last dimension denotes F or C contiguity
axis.step.analyse_types(env) axis.step.analyse_types(env)
if (not axis.step.type.is_int and axis.step.is_literal and not if (not axis.step.type.is_int and axis.step.is_literal and not
axis.step.type.is_error): axis.step.type.is_error):
...@@ -7347,7 +7348,8 @@ class CythonArrayNode(ExprNode): ...@@ -7347,7 +7348,8 @@ class CythonArrayNode(ExprNode):
if axis_no == 0: if axis_no == 0:
self.mode = "fortran" self.mode = "fortran"
elif axis.step and not first_or_last: elif not axis.step.is_none and not first_or_last:
# step provided in some other dimension
return error(axis.step.pos, ERR_STEPS) return error(axis.step.pos, ERR_STEPS)
if not self.operand.is_name: if not self.operand.is_name:
......
...@@ -60,3 +60,12 @@ my_c_contig = a33[0, :, :] ...@@ -60,3 +60,12 @@ my_c_contig = a33[0, :, :]
my_f_contig = a32[0, ...] my_f_contig = a32[0, ...]
my_c_contig = a33[0, ...] my_c_contig = a33[0, ...]
# Test casting to cython.view.array
cdef double[:, :] m1 = <double[:10, :10]> NULL
cdef double[:, :] m2 = <double[:10, :10:1]> NULL
cdef double[:, :] m3 = <double[:10:1, :10]> NULL
cdef double[:, :, :] m4 = <double[:10, :10, :10]> NULL
cdef double[:, :, :] m5 = <double[:10, :10, :10:1]> NULL
cdef double[:, :, :] m6 = <double[:10:1, :10, :10]> NULL
\ No newline at end of file
...@@ -102,15 +102,15 @@ def test_cython_array_index(): ...@@ -102,15 +102,15 @@ def test_cython_array_index():
print f_array[9, 8] print f_array[9, 8]
print f_array[6, 1] print f_array[6, 1]
cdef int *getp(int dim1=10, int dim2=10) except NULL: cdef int *getp(int dim1=10, int dim2=10, dim3=1) except NULL:
print "getp()" print "getp()"
cdef int *p = <int *> malloc(dim1 * dim2 * sizeof(int)) cdef int *p = <int *> malloc(dim1 * dim2 * dim3 * sizeof(int))
if p == NULL: if p == NULL:
raise MemoryError raise MemoryError
for i in range(dim1 * dim2): for i in range(dim1 * dim2 * dim3):
p[i] = i p[i] = i
return p return p
...@@ -161,6 +161,23 @@ def test_array_from_pointer(): ...@@ -161,6 +161,23 @@ def test_array_from_pointer():
c_arr.callback_free_data = callback_free_data c_arr.callback_free_data = callback_free_data
print c_arr[m - 1, n - 1] print c_arr[m - 1, n - 1]
def test_array_from_pointer_3d():
"""
>>> test_array_from_pointer_3d()
getp()
3 3
1 1
"""
cdef int *p = getp(2, 2, 2)
cdef array c_arr = <int[:2, :2, :2:1]> p
cdef array f_arr = <int[:2:1, :2, :2]> p
cdef int[:, :, ::1] m1 = c_arr
cdef int[::1, :, :] m2 = f_arr
print m1[0, 1, 1], m2[1, 1, 0]
print m1.is_c_contig(), m2.is_f_contig()
def test_cyarray_from_carray(): def test_cyarray_from_carray():
""" """
>>> test_cyarray_from_carray() >>> test_cyarray_from_carray()
......
...@@ -847,5 +847,4 @@ def test_dispatch_memoryview_object(): ...@@ -847,5 +847,4 @@ def test_dispatch_memoryview_object():
cdef int[:] m3 = <object> m cdef int[:] m3 = <object> m
test_fused_memslice(m3) test_fused_memslice(m3)
include "numpy_common.pxi" include "numpy_common.pxi"
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