Commit 4a9efd8d authored by Mark Florisson's avatar Mark Florisson

Nogil transpose

parent 71064916
...@@ -4196,10 +4196,6 @@ class AttributeNode(ExprNode): ...@@ -4196,10 +4196,6 @@ class AttributeNode(ExprNode):
elif self.type.is_memoryviewslice: elif self.type.is_memoryviewslice:
if self.is_memslice_transpose: if self.is_memslice_transpose:
# transpose the slice # transpose the slice
if self.in_nogil_context:
error(self.pos, "Cannot transpose slice in nogil mode")
return
for access, packing in self.type.axes: for access, packing in self.type.axes:
if access == 'ptr': if access == 'ptr':
error(self.pos, "Transposing not supported for slices " error(self.pos, "Transposing not supported for slices "
...@@ -4207,7 +4203,7 @@ class AttributeNode(ExprNode): ...@@ -4207,7 +4203,7 @@ class AttributeNode(ExprNode):
return return
code.putln("%s = %s;" % (self.result(), self.obj.result())) code.putln("%s = %s;" % (self.result(), self.obj.result()))
if self.obj.is_name: if self.obj.is_name or self.obj.is_attribute and self.obj.is_memslice_transpose:
code.put_incref_memoryviewslice(self.result(), have_gil=True) code.put_incref_memoryviewslice(self.result(), have_gil=True)
T = "__pyx_memslice_transpose(&%s) == 0" T = "__pyx_memslice_transpose(&%s) == 0"
...@@ -4259,7 +4255,8 @@ class AttributeNode(ExprNode): ...@@ -4259,7 +4255,8 @@ class AttributeNode(ExprNode):
elif self.type.is_memoryviewslice: elif self.type.is_memoryviewslice:
import MemoryView import MemoryView
MemoryView.put_assign_to_memviewslice( MemoryView.put_assign_to_memviewslice(
select_code, rhs.result(), self.type, code) select_code, rhs.result(), self.type, code,
incref_rhs=rhs.is_name)
if not self.type.is_memoryviewslice: if not self.type.is_memoryviewslice:
code.putln( code.putln(
......
...@@ -723,7 +723,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, ...@@ -723,7 +723,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
### Transposing a memoryviewslice ### Transposing a memoryviewslice
# #
@cname('__pyx_memslice_transpose') @cname('__pyx_memslice_transpose')
cdef int transpose_memslice({{memviewslice_name}} *memslice) except 0: cdef int transpose_memslice({{memviewslice_name}} *memslice) nogil except 0:
cdef int ndim = memslice.memview.view.ndim cdef int ndim = memslice.memview.view.ndim
cdef Py_ssize_t *shape = memslice.shape cdef Py_ssize_t *shape = memslice.shape
...@@ -737,9 +737,8 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) except 0: ...@@ -737,9 +737,8 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) except 0:
shape[i], shape[j] = shape[j], shape[i] shape[i], shape[j] = shape[j], shape[i]
if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0: if memslice.suboffsets[i] >= 0 or memslice.suboffsets[j] >= 0:
dim = i if memslice.suboffsets[i] >= 0 else j with gil:
raise ValueError("Cannot transpose view with indirect dimension " raise ValueError("Cannot transpose memoryview with indirect dimensions")
"(axis %d)" % dim)
return 1 return 1
......
...@@ -163,6 +163,13 @@ def test_transpose(): ...@@ -163,6 +163,13 @@ def test_transpose():
print a_obj.T.shape print a_obj.T.shape
print numpy_obj.T.shape print numpy_obj.T.shape
cdef dtype_t[:, :] c
with nogil:
c = a.T.T
assert (<object> a).shape == (<object> c).shape
assert (<object> a).strides == (<object> c).strides
print a[3, 2], a.T[2, 3], a_obj[3, 2], a_obj.T[2, 3], numpy_obj[3, 2], numpy_obj.T[2, 3] print a[3, 2], a.T[2, 3], a_obj[3, 2], a_obj.T[2, 3], numpy_obj[3, 2], numpy_obj.T[2, 3]
def test_coerce_to_numpy(): def test_coerce_to_numpy():
......
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