I want to create a python wrapper for my C++ library. It would be cool, if there is a automatic conversion of std::vector to python lists and the other way round. Unfortunatly if I add this code to my Interface-file I still get errors in run-time.
%typemap(in) std::vector<float> value (std::vector<float> vIn) {
int iLen = PySequence_Length($input);
for(unsigned int i = 0; i < iLen; i++) {
PyObject *o = PySequence_GetItem($input, i);
if (PyNumber_Check(o)) {
vIn.push_back((float)PyFloat_AsDouble(o) );
}
}
$1 = vIn;
}
%typemap(out) std::vector<float> {
std::vector<float> vOut = $1;
int iLen = vOut.size();
$result = PyList_New(iLen);
for(unsigned int i = 0; i < iLen; i++) {
double fVal = vOut.at(i);
PyObject *o = PyFloat_FromDouble((double) fVal);
PyList_SetItem($result, i, o);
}
}
Class header:
class TrainingSet {
private:
std::vector<std::vector<float> > m_vInputList;
std::vector<std::vector<float> > m_vOutputList;
public:
void AddInput(const std::vector<float> &vIn);
// ..
Python code:
trainSet = TrainingSet()
trainSet.AddInput([0.5, 0.5, 0.5])
Error:
File "runSOMNet.py", line 9, in <module>
trainSet.AddInput([0.5, 0.5, 0.5])
File "/home/dgrat/annetgpgpu/build/ANNet/ANPyNetCPU.py", line 674, in AddInput
def AddInput(self, *args): return _ANPyNetCPU.TrainingSet_AddInput(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'TrainingSet_AddInput'.
Possible C/C++ prototypes are:
ANN::TrainingSet::AddInput(std::vector< float,std::allocator< float > > const &)
ANN::TrainingSet::AddInput(float *,unsigned int const &)