From 5ddddeede553e60ea922c3a1545e692eaa572b86 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Tue, 28 Apr 2009 15:02:09 +0200 Subject: [PATCH] Simple fix for #155 --- Cython/Compiler/ExprNodes.py | 5 +++-- Cython/Compiler/Visitor.py | 1 + tests/run/numpy_bufacc_T155.pyx | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/run/numpy_bufacc_T155.pyx diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index b8d41ec0..c1bc8ea4 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1705,8 +1705,6 @@ class IndexNode(ExprNode): if self.indices: indices = self.indices else: - # On cloning, indices is cloned. Otherwise, unpack index into indices - assert not isinstance(self.index, CloneNode) if isinstance(self.index, TupleNode): indices = self.index.args else: @@ -1719,6 +1717,9 @@ class IndexNode(ExprNode): if not x.type.is_int: buffer_access = False + # On cloning, indices is cloned. Otherwise, unpack index into indices + assert not (buffer_access and isinstance(self.index, CloneNode)) + if buffer_access: self.indices = indices self.index = None diff --git a/Cython/Compiler/Visitor.py b/Cython/Compiler/Visitor.py index c7739f8d..6e40d858 100644 --- a/Cython/Compiler/Visitor.py +++ b/Cython/Compiler/Visitor.py @@ -150,6 +150,7 @@ class TreeVisitor(BasicVisitor): except Errors.CompileError: raise except Exception, e: + raise import sys trace = [''] for parent, attribute, index in self.access_path: diff --git a/tests/run/numpy_bufacc_T155.pyx b/tests/run/numpy_bufacc_T155.pyx new file mode 100644 index 00000000..7d0bb6b0 --- /dev/null +++ b/tests/run/numpy_bufacc_T155.pyx @@ -0,0 +1,15 @@ +""" +>>> myfunc() +0.5 +""" + +cimport numpy as np +import numpy as np + +def myfunc(): + cdef np.ndarray[float, ndim=2] A = np.ones((1,1), dtype=np.float32) + cdef int i + + for i from 0 <= i < A.shape[0]: + A[i, :] /= 2 + return A[0,0] -- 2.26.2