%typemapping of a C++ Library for Python Interface -
i want create python wrapper c++ library. cool, if there automatic conversion of std::vector python lists , other way round. unfortunatly if add code interface-file still errors in run-time.
%typemap(in) std::vector<float> value (std::vector<float> vin) { int ilen = pysequence_length($input); for(unsigned int = 0; < 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 = 0; < 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 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 &)
if you're going define %typemap
s manually, need %typemap(check)
, like:
%typemap(typecheck) std::vector<float>& { $1 = pysequence_check($input) ? 1 : 0; }
i believe rule of thumb if define %typemap(in)
, should define %typemap(check)
--- otherwise, generated code never gets it's put %typemap(in)
.
Comments
Post a Comment