boost-python

Is there a good way to send data from python context to C++ without too much copy involved

心不动则不痛 提交于 2019-12-12 03:12:01
问题 The title could be confusing. Here I will state my question more clearly. I want to create a website based on python (a lot of existing framework like Flask and cherryPy) and along with a C++ computation engine for the sake of processing speed. So I need to create an interface for python to call C++ functions. Fortunately the boost.python can do the job. However, every time I send a data from python, say a matrix, to C++, I have to use python list, which means I have to transform the matrix

boost.python caching wrapped class members

拈花ヽ惹草 提交于 2019-12-11 23:18:14
问题 I have a trivial classes dependency: class A { ... // constructor is omitted public: const std::string str1; }; class B { public: std::shared_ptr<A> a; } BOOST_PYTHON_IMPORT(wrapped) { class_<A, std::shared_ptr<A>>("APy") .def_readonly("str1", &A::str1); class_<B>("BPy") .def_readwrite("a", &B::a); } In Python import wrapped as wr b = wr.BPy() s1 = b.a.str1 // APy wrapper created s2 = b.a.str1 // new APy wrapper created even though object is the same Is there some way to create this APy

How to return a std::vector<const T*> to python?

耗尽温柔 提交于 2019-12-11 23:15:33
问题 I have a c++11 function that returns a: std::vector<const T*> f(); with T being a c++ class that I exposed to python with class_. All the T instances reside in static storage that will live throught the live of the python process. I am trying to expose f as a python function getAllTs() that would return python objects wrappers around T. I chose T* to be the held type for class_. I am converting std::vector to a python tuple, with this bad semi-generic function: template <typename Cont> struct

LNK1181: cannot open input file 'boost_python.lib' in windows, boost_1_68_0

此生再无相见时 提交于 2019-12-11 17:32:55
问题 I downloaded and built boost_1_68_0 (bootstrap and b2) with VS 14 on Windows 10. I verified the build by running bjam in the lib\regex\example folder, which ran without error. When I try to do the same thing in the lib\python\example folder I get this error for each link: LNK1181: cannot open input file 'boost_python.lib' I verified that the boost_python.lib variants (libboost_python36-vc140-mt-gd-x32-1_68.lib, libboost_python36-vc140-mt-x32-1_68.lib, and x64 versions) are in the F:\Dev\Boost

weird object returned by vector_indexing_suite

烈酒焚心 提交于 2019-12-11 14:25:27
问题 I have a std::vector<const T*> that I return from a c++ function: getallTs() I have exposed the T class with: class_<T,T*> and the vector like so: class_<std::vector<const T*> >("TsList") .def(vector_indexing_suite<std::vector<const T*>,true>()) ; What does the NoProxy argument mean? I expose the function like so: def("getallTs", getallTs, return_value_policy<return_by_value>{}); I observe a weird behaviour. When I call from python tlist = getallTs() I get a TsList object. len(tlist) works.

Expose C++ member function that has std::function as argument with boost::python

不羁的心 提交于 2019-12-11 13:37:51
问题 I have a class that contains an attribute which is a std::function. I set the value of this attribute using a member function, so the class looks like this: class ClassName { public: void SetCallbackFunction(std::function<void (int i)> callbackFun) { m_callbackFunction = callbackFun; } protected: std::function<void (int i)> m_callbackFunction; }; I need to expose this class to Python and, of course, I need to expose the SetCallbackFunction function. How can I do this with boost::python? 回答1:

boost.python argument type mismatch (numpy.int64 -> int)

孤者浪人 提交于 2019-12-11 13:22:09
问题 I'm running into this problem: Boost.Python.ArgumentError: Python argument types in Dirichlet.Observe(int, numpy.int64, float) did not match C++ signature: Observe(unsigned int, unsigned int, double) Seems close enough? After doing some replacement, it seems that the middle argument is the problem. How do I convert numpy.int64 to int? 回答1: You could you try... int(numpyint) 来源: https://stackoverflow.com/questions/4383515/boost-python-argument-type-mismatch-numpy-int64-int

Unresolved Error when building Boost.Python

被刻印的时光 ゝ 提交于 2019-12-11 11:15:02
问题 I am trying to run an example during installation of Boost.Python on my Windows7 64-bit machine. My boost is installed at C:\local\boost_1_54_0 . Thus at step 3.1.4, I entered b2 toolset=msvc --build-type=complete --verbose-test test However, in the command prompt window, I've got 135 unresolved external errors. These errors all point to a serie of files that has the same prefix boost_python-vc110-gd-1_54 , the extentions are such as .rsp , .dll etc., and they should be at C:\local\boost_1_54

Boost Python Embedding Error

走远了吗. 提交于 2019-12-11 09:44:55
问题 I've just built Boost Python on Windows 10 with an Anaconda version of Python 3.5 (64 bit). I used these instructions modified to my suit my installation and have successfully built the testCode.cpp using Visual Studio 2015: #include <boost/python.hpp> using namespace boost::python; int main() { try { Py_Initialize(); object main_module(( handle<>(borrowed(PyImport_AddModule("__main__"))))); object main_namespace = main_module.attr("__dict__"); handle<> ignored(( PyRun_String( "print (\"Hello

Segfault from passing a shared pointer between C++ objects via Boost Python

感情迁移 提交于 2019-12-11 08:29:36
问题 I have two custom C++ classes Foo and Baz that I've successfully exposed to Python via Boost Python; the user interacts with Python classes that run their C++ counterparts under the hood. An important use case is passing a Foo Python instance to a Python method Baz.run_that_foo . The Python bindings method is, // Note `XPython` is the name for the Boost Python bindings class of `X`. void BazPython::RunThatFoo(const bp::object & foo) { FooPython & foo_obj = bp::extract<FooPython&>(foo); auto