0

I try to cythonize the following code:

from libcpp.vector import vector
from libcpp cimport bool

def test():
   cdef vector[bool] = pos(top, 0)

return 1

with:

cython test.pyx --cplus -o test.cpp

which however results in:

Error compiling Cython file:

------------------------------------------------------------

...

from libcpp.vector import vector
from libcpp cimport bool

def test():
cdef vector[bool] = pos(top, 0)
              ^
------------------------------------------------------------

test.pyx:5:19: Empty declarator

Error compiling Cython file:
------------------------------------------------------------
...
from libcpp.vector import vector
from libcpp cimport bool

def test():
    cdef vector[bool] = pos(top, 0)
              ^
------------------------------------------------------------

I assume I'm missing something simple to use c++ but I can't figure out what exactly. Any help would be greatly appropriated.

6
  • 1
    I know nothing about cython, but aren't you missing a name for the thing you're defining?
    – Mat
    Feb 9, 2015 at 9:53
  • 1
    What is that cdef supposed to say. It doesn't make sense as either Python or C / C++ to me.
    – Stephen C
    Feb 9, 2015 at 9:55
  • @StephenC cdef is supposed to introduce c/c++ datatypes.
    – magu_
    Feb 9, 2015 at 10:19
  • @StephenC: that's a cython definition, it gives python-like code c/c++ definitions for performance purposes, here's an example: docs.cython.org/src/userguide/…
    – Wolph
    Feb 9, 2015 at 10:19
  • @Mat of course your totally right. I did screw up by the creation of the mwe. Thanks for solving the problem for me.
    – magu_
    Feb 9, 2015 at 10:26

1 Answer 1

4

You appear to have 2 problems in your code:

  1. the vector is imported using import instead of cimport.
  2. the vector[bool] doesn't get a name, just a type definition.

Here's an example of working code for me:

from libcpp.vector cimport vector
from libcpp cimport bool

cdef vector[bool] your_vector
1
  • Yes this was it. I don't know how I overlooked this. Thank you for pointing it out to me.
    – magu_
    Feb 9, 2015 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.