无法将自定义ctypedef类的cython向量设置为公共 我有一个类,它拥有一个C++类成员,它保存自定义类对象。我希望能够从python中以列表的形式读取此向量,但我无法以任何方式进行读取

无法将自定义ctypedef类的cython向量设置为公共 我有一个类,它拥有一个C++类成员,它保存自定义类对象。我希望能够从python中以列表的形式读取此向量,但我无法以任何方式进行读取,c++,python,vector,cython,public,C++,Python,Vector,Cython,Public,我的标题: from __future__ import division import cython from libcpp.vector cimport vector #this import the C++ vector, which #is compatible with python lists import numpy as np cimport numpy as np #@

我的标题:

from __future__ import division

import cython               
from libcpp.vector cimport vector   #this import the C++ vector, which
                                    #is compatible with python lists
import numpy as np
cimport numpy as np

#@cython.boundscheck(False) #this line remove some correct checking for
                            #for bounds, which makes it hard to debug
                            #but also faster
这是我的自定义类:

ctypedef class boid:
    """Placeholder for the boids"""
    cdef public vector[double] pos  #position of the boid
    cdef public vector[double] vel  #velocity of the boid

    def __init__(self, vector[double] pos_):
        self.pos = pos_
这是另一个类,有向量

cdef class csopsim:
    """This is the simulation"""
    #declaring c variable types
    cdef vector[boid] boids  #list of boids

    def __init__(self,int scenario):
        #setting default values
        self.BOX_SIZE = 640
        self.BOX = float(self.BOX_SIZE)

        self.NUM_MALES = 10
        for x in xrange(self.NUM_MALES):
            self.boids.push_back(boid(0,np.random.uniform(350,450,2)))
这可以很好地编译,但显然,试图获取csopsim.boids会抛出一个无属性错误。如果我将其修改为

cdef public vector[boid] boids
它不能编译。如果我创建一个方法

def getboids(self):
    return self.boids
cdef vector[boid] getboids(self):
    return self.boids
它不能编译。如果我创建一个方法

def getboids(self):
    return self.boids
cdef vector[boid] getboids(self):
    return self.boids

它可以编译,但当我试图从python调用该方法时,它抛出一个AttributeError:“csopsim.csopsim”对象没有属性“getboids”。我希望这个问题有一个简单而琐碎的解决方案:“

< p>我使用了CythoNoice纯C++类,而这似乎是可行的,而且更简单。