Opened 6 years ago

Closed 6 years ago

#155 closed defect (fixed)

AssertionError w/ CloneNode when mixing python objects, buffers, and +=

Reported by: hoytak Owned by: dagss
Priority: minor Milestone: 0.11.2
Component: Code Generation Keywords: numerics
Cc:

Description

Hello,

In cython version 1474:7f1b96cad687, the following code segments both cause an identical AssertionError? in the cython compiler. The common issue seems to be mixing the python objects with buffers under the loop. (I've tried other examples, but couldn't reproduce it beyond these).

In this one, there is the slice object:

from numpy cimport ndarray as ar
import numpy as np

def myfunc(self):
    cdef ar[float, ndim=2] A = np.ones( (1,1) )
    cdef int i

    for i from 0 <= i < A.shape[0]:
        A[i, :] /= 2

and in this one the i is not declared as a c variable.

from numpy cimport ndarray as ar
import numpy as np

def myfunc(self):
    cdef ar[float] b = np.ones(1)

    for i in range(b.shape[0]):
        b[i] /= 2

The problem also shows up for *=, +=, etc.

Both of these raise the following assertion error:

  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Distutils/build_ext.py", line 81, in build_extensions                                                 
    ext.sources = self.cython_sources(ext.sources, ext)                                                                                                               
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Distutils/build_ext.py", line 196, in cython_sources                                                  
    full_module_name=module_name)                                                                                                                                     
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 703, in compile                                                               
    return compile_single(source, options, full_module_name)                                                                                                          
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 648, in compile_single
    return run_pipeline(source, options, full_module_name)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 537, in run_pipeline
    err, enddata = context.run_pipeline(pipeline, source)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Main.py", line 196, in run_pipeline
    data = phase(data)
  File "Visitor.py", line 177, in Cython.Compiler.Visitor.CythonTransform.__call__ (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:2365)
  File "Visitor.py", line 163, in Cython.Compiler.Visitor.VisitorTransform.__call__ (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:2109)
  File "Visitor.py", line 43, in Cython.Compiler.Visitor.BasicVisitor.visit (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:955)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/ParseTreeTransforms.py", line 668, in visit_ModuleNode
    self.visitchildren(node)
  File "Visitor.py", line 146, in Cython.Compiler.Visitor.VisitorTransform.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1782)
  File "Visitor.py", line 119, in Cython.Compiler.Visitor.TreeVisitor.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1576)
  File "Visitor.py", line 95, in Cython.Compiler.Visitor.TreeVisitor.visitchild (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1185)
  File "Visitor.py", line 43, in Cython.Compiler.Visitor.BasicVisitor.visit (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:955)
  File "Visitor.py", line 187, in Cython.Compiler.Visitor.CythonTransform.visit_Node (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:2596)
  File "Visitor.py", line 146, in Cython.Compiler.Visitor.VisitorTransform.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1782)
  File "Visitor.py", line 117, in Cython.Compiler.Visitor.TreeVisitor.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1538)
  File "Visitor.py", line 95, in Cython.Compiler.Visitor.TreeVisitor.visitchild (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1185)
  File "Visitor.py", line 43, in Cython.Compiler.Visitor.BasicVisitor.visit (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:955)
  File "Visitor.py", line 187, in Cython.Compiler.Visitor.CythonTransform.visit_Node (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:2596)
  File "Visitor.py", line 146, in Cython.Compiler.Visitor.VisitorTransform.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1782)
  File "Visitor.py", line 117, in Cython.Compiler.Visitor.TreeVisitor.visitchildren (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1538)
  File "Visitor.py", line 95, in Cython.Compiler.Visitor.TreeVisitor.visitchild (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:1185)
  File "Visitor.py", line 43, in Cython.Compiler.Visitor.BasicVisitor.visit (/home/hoytak/sysroot/src/cython/Cython/Compiler/Visitor.c:955)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/ParseTreeTransforms.py", line 672, in visit_FuncDefNode
    node.body.analyse_expressions(node.local_scope)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 318, in analyse_expressions
    stat.analyse_expressions(env)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 3860, in analyse_expressions
    self.body.analyse_expressions(env)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 318, in analyse_expressions
    stat.analyse_expressions(env)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 2679, in analyse_expressions
    self.analyse_types(env)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/Nodes.py", line 2970, in analyse_types
    self.lhs.analyse_target_types(env)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/ExprNodes.py", line 1609, in analyse_target_types
    self.analyse_base_and_index_types(env, setting = 1)
  File "/home/hoytak/sysroot/lib/python2.5/site-packages/Cython/Compiler/ExprNodes.py", line 1634, in analyse_base_and_index_types
    assert not isinstance(self.index, CloneNode)
AssertionError

Note also that replacing the += works:

from numpy cimport ndarray as ar
import numpy as np

def myfunc(self):
    cdef ar[float] b = np.ones(1)

    for i in range(b.shape[0]):
        b[i] = b[i] + 2

As well as cdef'ing the i:

from numpy cimport ndarray as ar
import numpy as np

def myfunc(self):
    cdef ar[float] b = np.ones(1)
    cdef int i 

    for i in range(b.shape[0]):
        b[i] += 2

--Hoyt

Change History (6)

comment:1 Changed 6 years ago by dagss

  • Cc numerics added
  • Milestone changed from wishlist to 0.11.2

I'm the likely suspect for doing this one (though I'll wait with assigning it until I can do some work).

comment:2 Changed 6 years ago by dagss

  • Cc numerics removed
  • Keywords numerics added

comment:3 Changed 6 years ago by dagss

  • Resolution set to fixed
  • Status changed from new to closed

comment:4 Changed 6 years ago by dagss

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:5 Changed 6 years ago by dagss

  • Owner changed from somebody to dagss
  • Status changed from reopened to new

comment:6 Changed 6 years ago by dagss

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.