Cython Compile error: Cannot convert to Python object

1,154 views
Skip to first unread message

austin aigbe

unread,
Jul 28, 2017, 5:29:24 PM7/28/17
to cython-users
Hello,

Kindly assist in resolving the following errors:

Compiling mapping.pyx because it changed.
[1/1] Cythonizing mapping.pyx

Error compiling Cython file:
------------------------------------------------------------
...

  def set_n(self, int input_, int n):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_
                 ^
------------------------------------------------------------

mapping.pyx:57:18: Cannot assign to or delete this

Error compiling Cython file:
------------------------------------------------------------
...

  def set_point(self, int input_, int index, float x, float y):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (index >= 0) and (index < 8)

    ControlPoints * p = self.points_list + input_
                 ^
------------------------------------------------------------

mapping.pyx:73:18: Cannot assign to or delete this

Error compiling Cython file:
------------------------------------------------------------
...
    # constant mapping (common case)
    if (self.inputs_used == 0):
      return result

    for j in range(self.inputs):
      ControlPoints *p = self.points_list + j
                   ^
------------------------------------------------------------

mapping.pyx:98:20: Cannot assign to or delete this

Error compiling Cython file:
------------------------------------------------------------
...

  def set_n(self, int input_, int n):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_
                 ^
------------------------------------------------------------

mapping.pyx:57:18: 'ControlPoints' is not a constant, variable or function identifier

Error compiling Cython file:
------------------------------------------------------------
...

  def set_n(self, int input_, int n):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_
                    ^
------------------------------------------------------------

mapping.pyx:57:21: undeclared name not builtin: p

Error compiling Cython file:
------------------------------------------------------------
...

  def set_n(self, int input_, int n):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_
                                       ^
------------------------------------------------------------

mapping.pyx:57:40: Cannot convert 'ControlPoints *' to Python object

Error compiling Cython file:
------------------------------------------------------------
...
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_

    if (n != 0) and (p.n == 0):
      self.points_list = self.inputs_used + 1
                                         ^
------------------------------------------------------------

mapping.pyx:60:42: Cannot assign type 'long' to 'ControlPoints *'

Error compiling Cython file:
------------------------------------------------------------
...

  def set_point(self, int input_, int index, float x, float y):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (index >= 0) and (index < 8)

    ControlPoints * p = self.points_list + input_
                 ^
------------------------------------------------------------

mapping.pyx:73:18: 'ControlPoints' is not a constant, variable or function identifier

Error compiling Cython file:
------------------------------------------------------------
...

  def set_point(self, int input_, int index, float x, float y):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (index >= 0) and (index < 8)

    ControlPoints * p = self.points_list + input_
                                        ^
------------------------------------------------------------

mapping.pyx:73:41: Cannot convert 'ControlPoints *' to Python object

Error compiling Cython file:
------------------------------------------------------------
...
    # constant mapping (common case)
    if (self.inputs_used == 0):
      return result

    for j in range(self.inputs):
      ControlPoints *p = self.points_list + j
                   ^
------------------------------------------------------------

mapping.pyx:98:20: 'ControlPoints' is not a constant, variable or function identifier

Error compiling Cython file:
------------------------------------------------------------
...
    # constant mapping (common case)
    if (self.inputs_used == 0):
      return result

    for j in range(self.inputs):
      ControlPoints *p = self.points_list + j
                                         ^
------------------------------------------------------------

mapping.pyx:98:42: Cannot convert 'ControlPoints *' to Python object
Traceback (most recent call last):
  File "setup.py", line 11, in <module>
    ext_modules = cythonize("mapping.pyx")
  File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 915, in cythonize
    cythonize_one(*args)
  File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 1037, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: mapping.pyx


Code:

from libc.stdlib cimport *
  
cdef struct ControlPoints:
  float xvalues[8]
  float yvalues[8]
  int n

# user-defined mappings
# (the curves you can edit in the brush settings)

cdef class Mapping:
  cdef ControlPoints *points_list
  cdef int inputs_used
  cdef float base_value
  cdef int inputs

  def __cinit__(self):
    self.points_list = NULL

  def __init__(self, int inputs_):
    self.inputs = inputs = inputs_
    self.points_list = <ControlPoints*> malloc(sizeof(ControlPoints)*inputs_) # one for each input

    cdef int i = 0
    for i in range(inputs_):
      self.points_list[i].n = 0

    self.inputs_used = 0
    self.base_value = 0

  def __dealloc__(self):
    if (self.points_list != NULL):
      free(self.points_list)

  def set_n(self, int input_, int n):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (n >= 0) and (n <= 8)
    assert (n != 1)
    ControlPoints *p = self.points_list + input_

    if (n != 0) and (p.n == 0):
      self.points_list = self.inputs_used + 1
    if (n == 0) and (p.n != 0):
      self.inputs_used = self.inputs_used - 1

    assert(self.inputs_used >= 0)
    assert(self.inputs_used <= self.inputs)

    p.n = n

def set_point(self, int input_, int index, float x, float y):
    assert (input_ >= 0) and (input_ < self.inputs)
    assert (index >= 0) and (index < 8)

    ControlPoints * p = self.points_list + input_
    assert (index < p.n)

    if (index > 0):
      assert x >= p.xvalues[index-1]

    p.xvalues[index] = x
    p.yvalues[index] = y

  def is_constant(self):
    return self.inputs_used == 0
Reply all
Reply to author
Forward
0 new messages