Sto cercando disperatamente di esporre un membro della classe std::vector<bool>
a una classe Python.problema cython: 'bool' non è un identificatore di tipo
Qui è la mia classe C++:
class Test
{
public:
std::vector<bool> test_fail;
std::vector<double> test_ok;
};
Mentre l'accesso e la conversione di test_ok
di tipo double
(o int, float, ..) funziona, non lo fa per bool
!
Ecco la mia classe Cython:
cdef class pyTest:
cdef Test* thisptr
cdef public vector[bool] test_fail
cdef public vector[double] test_ok
cdef __cinit__(self):
self.thisptr = new Test()
self.test_fail = self.thisptr.test_fail # compiles and works if commented
self.test_ok = self.thisptr.test_ok
cdef __dealloc__(self):
del self.thisptr
L'errore che ottengo è:
Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from *:
ctypedef bool X 'bool'
^
------------------------------------------------------------
vector.from_py:37:13: 'bool' is not a type identifier
sto usando Python 2.7.6 e 0.20.2 Cython (anche provato 0.20.1) .
Ho provato anche con le proprietà ma non funziona neanche.
Addendum: Ho il from libcpp cimport bool
nella parte superiore del mio file pyx, così come l'importazione del vettore.
Cosa c'è che non va ?? Credo che questo potrebbe essere un bug. Qualcuno sa come aggirare questo? Grazie.
Il wiki Cython è molto utile per quanto riguarda questo problema: https://github.com/cython/cython/wiki/FAQ#id49 –