Reputation: 1624
I have a function and I am trying to return a number and a vector of ints. What I have is
cdef func() nogil:
cdef vector[int] vect
cdef int a_number
...
return a_number, vect
but this will give errors like Assignment of Python object not allowed without gil
. Is there a workaround?
Upvotes: 8
Views: 4731
Reputation: 998
Cython has a ctuple
type http://docs.cython.org/en/latest/src/userguide/language_basics.html#types
%%cython -a -f -+
from libcpp.vector cimport vector
cdef (vector[int], double) func() nogil:
cdef vector[int] vec
cdef double d = 3.14
cdef int i
for i in range(10):
vec.push_back(i)
return vec, d
Upvotes: 13
Reputation: 26110
You need to return a C++ structure: a struct, a vector, an std::pair, etc, not a python tuple object.
Upvotes: 0