From gr at componic.co.nz Wed Aug 1 02:07:08 2012 From: gr at componic.co.nz (Glenn Ramsey) Date: Wed, 01 Aug 2012 12:07:08 +1200 Subject: [C++-sig] How to create a custom exception derived from Exception In-Reply-To: <5017BA3F.6060403@gmail.com> References: <5017A1FA.8050502@componic.co.nz> <5017BA3F.6060403@gmail.com> Message-ID: <5018732C.3090309@componic.co.nz> On 31/07/12 22:58, Jim Bosch wrote: > On 07/31/2012 06:14 PM, Glenn Ramsey wrote: >> >> Using boost::python how can I create an a custom exception that is >> derived from Python's Exception? The functionality I would like to get >> by doing this is to provide additional methods for the catching code to >> retrieve information from the exception. >> > > The approach I've taken in the past (sorry, don't have an example right now) is > to raise a true Python exception (from PyErr_NewException), and attach your > Boost.Python-wrapped C++ exception to it as an instance variable. Then put a > __getattr__ in the true Python exception that forwards to the Boost.Python > object it holds. > > I can try to reconstruct more details if needed, but hopefully that's enough to > get you started. Thanks, based on that I have done this, which seems to work, but I'm not sure if it is entirely correct. I didn't need to implement __getattr__ and would be interested in seeing some more details of your approach. PyObject *exceptionType=NULL; // will be initialised inside BOOST_PYTHON_MODULE(...) using createExceptionClass(...) void translator(const MyCPPException &x) { bp::object exc(x); bp::object exc_t(bp::handle<>(bp::borrowed(exceptionType))); exc_t.attr("cause") = exc; PyErr_SetString(exceptionType, x.what()); } PyObject* createExceptionClass(const char* name, PyObject* baseTypeObj = PyExc_Exception) { std::string scopeName = bp::extract(qualifiedName0.c_str()); PyObject* typeObj = PyErr_NewException(qualifiedName1, baseTypeObj, 0); if(!typeObj) { bp::throw_error_already_set(); } bp::scope().attr(name) = bp::handle<>(bp::borrowed(typeObj)); return typeObj; } BOOST_PYTHON_MODULE(MyModule) { bp::register_exception_translator(translator); .... bp::class_("MyCPPException") .def(...); exceptionType = createExceptionClass("MyCPPExceptionType"); .... } In Python: try: ... except MyModule.MyCPPExceptionType as e: cause = e.cause # wrapped exception can be accessed here ... Glenn From talljimbo at gmail.com Thu Aug 2 05:28:21 2012 From: talljimbo at gmail.com (Jim Bosch) Date: Thu, 02 Aug 2012 12:28:21 +0900 Subject: [C++-sig] How to create a custom exception derived from Exception In-Reply-To: <5018732C.3090309@componic.co.nz> References: <5017A1FA.8050502@componic.co.nz> <5017BA3F.6060403@gmail.com> <5018732C.3090309@componic.co.nz> Message-ID: <5019F3D5.4020700@gmail.com> On 08/01/2012 09:07 AM, Glenn Ramsey wrote: > On 31/07/12 22:58, Jim Bosch wrote: >> On 07/31/2012 06:14 PM, Glenn Ramsey wrote: >>> >>> Using boost::python how can I create an a custom exception that is >>> derived from Python's Exception? The functionality I would like to get >>> by doing this is to provide additional methods for the catching code to >>> retrieve information from the exception. >>> >> >> The approach I've taken in the past (sorry, don't have an example >> right now) is >> to raise a true Python exception (from PyErr_NewException), and attach >> your >> Boost.Python-wrapped C++ exception to it as an instance variable. >> Then put a >> __getattr__ in the true Python exception that forwards to the >> Boost.Python >> object it holds. >> >> I can try to reconstruct more details if needed, but hopefully that's >> enough to >> get you started. > > Thanks, based on that I have done this, which seems to work, but I'm not > sure if it is entirely correct. I didn't need to implement __getattr__ > and would be interested in seeing some more details of your approach. > Looks fine to me. I'm afraid I don't really have any more details - I last did this a while ago, and I don't exactly remember where it was anymore. But it seems pretty similar to what I did. Jim From josh.davidson at lmco.com Sun Aug 12 23:55:40 2012 From: josh.davidson at lmco.com (Davidson, Josh) Date: Sun, 12 Aug 2012 21:55:40 +0000 Subject: [C++-sig] pygccxml isn't working with Python 2.7 win64 Message-ID: <86299D4CFE2C1248AA41ACF782B0D143118FD575@HDXDSP33.us.lmco.com> I recently updated to Python 2.7 from Python 2.6 and am running into issues with pygccxml. Previously, I was on: Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32 I'm now on: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 On both systems, I have the latest versions of pygccxml/py++ installed from SVN. I've diff'd the versions installed in both interpreter's site-packages directory and they match exactly. When I run on Python 2.7.3, the suprocess call to gccxml barfs. Here is an example: INFO Parsing source file "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" ... INFO gccxml cmd: ""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I ExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python27\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterf "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmp0h9nvf.xml"" COMMAND LINE*""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I"D:\ rnalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python27\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces \SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmp0h9nvf.xml""* LENGTH 433 LINE The input line is too long. LINE LINE Traceback (most recent call last): File "C:\Python27\lib\site-packages\pygccxml\parser\source_reader.py", line 229, in read_gccxml_file gccxml_file = self.create_xml_file( ffname ) File "C:\Python27\lib\site-packages\pygccxml\parser\source_reader.py", line 185, in create_xml_file raise error gccxml_runtime_error_t: Error occured while running GCC-XML: The input line is too long. ffname D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp There are a few extra print statements at the end, which line up to some debugging code I inserted into source_reader.py: print "COMMAND LINE*%s*" % (command_line,) print type(command_line) print "LENGTH", len(command_line) The few lines beginning with "LINE" are just prints from the loop that reads the stdout pipe after spawning gccxml. As you can see, the line is only 433 characters which is well within Windows limits. I've moved the project all over the place and no matter where it's at, I get this error. If I switch back to Python26, this is what I get: INFO Parsing source file "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" ... INFO gccxml cmd: ""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I ExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python26\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterf "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmpdgchpg.xml"" COMMAND LINE*""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I"D:\ rnalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python26\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces \SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmpdgchpg.xml""* LENGTH 433 LINE INFO GCCXML version - 0.9( 1.135 ) As you can see, the command line is basically the same save the references to the different Python installation. Length is also the same. It appears that someting in subprocess changed in 2.7 that doesn't play nicely with how gccxml is being launched. From josh.davidson at lmco.com Mon Aug 13 00:51:14 2012 From: josh.davidson at lmco.com (Davidson, Josh) Date: Sun, 12 Aug 2012 22:51:14 +0000 Subject: [C++-sig] pygccxml isn't working with Python 2.7 win64 In-Reply-To: <86299D4CFE2C1248AA41ACF782B0D143118FD596@HDXDSP33.us.lmco.com> References: <86299D4CFE2C1248AA41ACF782B0D143118FD575@HDXDSP33.us.lmco.com> <86299D4CFE2C1248AA41ACF782B0D143118FD596@HDXDSP33.us.lmco.com> Message-ID: <86299D4CFE2C1248AA41ACF782B0D143118FD5A8@HDXDSP33.us.lmco.com> Let's try this once more... 122c122 < cmd_line = '"%s"' % cmd_line --- > cmd_line = '%s' % cmd_line 154c154 < , shell=True --- > , shell=False if 'nt' == os.name else True Command line isn't being split, so shell=True is required for *nix. ________________________________________ From: Davidson, Josh Sent: Sunday, August 12, 2012 4:40 PM To: cplusplus-sig at python.org Subject: RE: pygccxml isn't working with Python 2.7 win64 Here is a patch that works for both 2.6 & 2.7: D:\SimExternalInterfaces>diff C:\temp\pygccxml\pygccxml_dev\pygccxml\parser\source_reader.py C:\Python27\Lib\site-packages\pygccxml\parser\source_reader.py 122c122 < cmd_line = '"%s"' % cmd_line --- > cmd_line = '%s' % cmd_line 154c154 < , shell=True --- > , shell=False From josh.davidson at lmco.com Mon Aug 13 00:40:14 2012 From: josh.davidson at lmco.com (Davidson, Josh) Date: Sun, 12 Aug 2012 22:40:14 +0000 Subject: [C++-sig] pygccxml isn't working with Python 2.7 win64 In-Reply-To: <86299D4CFE2C1248AA41ACF782B0D143118FD575@HDXDSP33.us.lmco.com> References: <86299D4CFE2C1248AA41ACF782B0D143118FD575@HDXDSP33.us.lmco.com> Message-ID: <86299D4CFE2C1248AA41ACF782B0D143118FD596@HDXDSP33.us.lmco.com> Here is a patch that works for both 2.6 & 2.7: D:\SimExternalInterfaces>diff C:\temp\pygccxml\pygccxml_dev\pygccxml\parser\source_reader.py C:\Python27\Lib\site-packages\pygccxml\parser\source_reader.py 122c122 < cmd_line = '"%s"' % cmd_line --- > cmd_line = '%s' % cmd_line 154c154 < , shell=True --- > , shell=False ________________________________________ From: Davidson, Josh Sent: Sunday, August 12, 2012 3:55 PM To: cplusplus-sig at python.org Subject: pygccxml isn't working with Python 2.7 win64 I recently updated to Python 2.7 from Python 2.6 and am running into issues with pygccxml. Previously, I was on: Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32 I'm now on: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 On both systems, I have the latest versions of pygccxml/py++ installed from SVN. I've diff'd the versions installed in both interpreter's site-packages directory and they match exactly. When I run on Python 2.7.3, the suprocess call to gccxml barfs. Here is an example: INFO Parsing source file "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" ... INFO gccxml cmd: ""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I ExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python27\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterf "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmp0h9nvf.xml"" COMMAND LINE*""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I"D:\ rnalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python27\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces \SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmp0h9nvf.xml""* LENGTH 433 LINE The input line is too long. LINE LINE Traceback (most recent call last): File "C:\Python27\lib\site-packages\pygccxml\parser\source_reader.py", line 229, in read_gccxml_file gccxml_file = self.create_xml_file( ffname ) File "C:\Python27\lib\site-packages\pygccxml\parser\source_reader.py", line 185, in create_xml_file raise error gccxml_runtime_error_t: Error occured while running GCC-XML: The input line is too long. ffname D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp There are a few extra print statements at the end, which line up to some debugging code I inserted into source_reader.py: print "COMMAND LINE*%s*" % (command_line,) print type(command_line) print "LENGTH", len(command_line) The few lines beginning with "LINE" are just prints from the loop that reads the stdout pipe after spawning gccxml. As you can see, the line is only 433 characters which is well within Windows limits. I've moved the project all over the place and no matter where it's at, I get this error. If I switch back to Python26, this is what I get: INFO Parsing source file "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" ... INFO gccxml cmd: ""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I ExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python26\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterf "D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmpdgchpg.xml"" COMMAND LINE*""C:\MinGW\bin\gccxml.exe" -DBOOST_NO_RVALUE_REFERENCES -D__mode__(x)= -DMS_WIN64 -I"." -I"D:\SimExternalInterfaces\src\C++" -I"D:\ rnalInterfaces\src\C++\SimInterfaces\SimExecInterfaces" -I"C:\Python26\include" -I"D:\SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces \SimExternalInterfaces\src\C++\SimInterfaces\SimExecInterfaces\temp.executive.hpp" -fxml="c:\users\josh\appdata\local\temp\tmpdgchpg.xml""* LENGTH 433 LINE INFO GCCXML version - 0.9( 1.135 ) As you can see, the command line is basically the same save the references to the different Python installation. Length is also the same. It appears that someting in subprocess changed in 2.7 that doesn't play nicely with how gccxml is being launched. From atalay at udel.edu Tue Aug 14 01:05:25 2012 From: atalay at udel.edu (Murat Atalay) Date: Mon, 13 Aug 2012 16:05:25 -0700 Subject: [C++-sig] Interact python with C++ Message-ID: Hello Everyone, Currently, I am trying to call C++ classes and functions from python inside my C++ program. I want to be able to edit the members and call functions from python. I am using VS2010 with boost libraries. Boost comes with very big embedding frame work and SWIG mix of C and C++ files and I don't want to create DLLs. So, I was wondering if there is another tool to interact python with C++ and vise versa. I also have an issue when I use boost. I keep getting an python version mismatch error. I was wondering what could cause this. Regards, Murat -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Tue Aug 14 11:32:16 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Tue, 14 Aug 2012 10:32:16 +0100 Subject: [C++-sig] Interact python with C++ In-Reply-To: References: Message-ID: On 14/08/12 00:05, Murat Atalay wrote: > Hello Everyone, > > Currently, I am trying to call C++ classes and functions from python > inside my C++ program. I want to be able to edit the members and call > functions from python. I am using VS2010 with boost libraries. Boost > comes with very big embedding frame work and SWIG mix of C and C++ files > and I don't want to create DLLs. So, I was wondering if there is another > tool to interact python with C++ and vise versa. What do you mean "edit the members"? Also, I'm not sure how you can interact with C++ from python without creating a DLL. > > I also have an issue when I use boost. I keep getting an python version > mismatch error. I was wondering what could cause this. It is hard to help without significantly more information. Regards, John. From alfarobi0161 at yahoo.com Tue Aug 14 13:25:25 2012 From: alfarobi0161 at yahoo.com (shahmi) Date: Tue, 14 Aug 2012 19:25:25 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ Message-ID: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> Hi, I have tried to access/expose 2D array from python in C++ using boost::multi_array. Nevertheless, it seems that the boost::multi_array?datatype is not supported. Is there any way to resolve this? My way of accessing it as below: ? ? ? ? ? ? boost::python::object Vp = main_namespace["Vp"]; ? ? ? ? ? ? Vp_cpp = boost::python::extract?>(Vp); I've also tried to try to use 2D vector as below, nonetheless, it still doesn't work: ??? ??? boost::python::object Vp = main_namespace["Vp"]; ??? ??? Vp_cpp = boost::python::extract > >(Vp); The error message I received is "TypeError: No registered converter was able to produce a C++ rvalue of type std::vector >, std::allocator > > > from this Python object of type matrix" Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_sourceforge at nedprod.com Tue Aug 14 13:34:33 2012 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Tue, 14 Aug 2012 12:34:33 +0100 Subject: [C++-sig] Interact python with C++ In-Reply-To: References: Message-ID: <502A37C9.3972.A295A98@s_sourceforge.nedprod.com> Could use Cython. You're still going to have to use DLLs though. With Python it's very hard to avoid DLLs. Niall On 13 Aug 2012 at 16:05, Murat Atalay wrote: > Hello Everyone, > > Currently, I am trying to call C++ classes and functions from python inside > my C++ program. I want to be able to edit the members and call functions > from python. I am using VS2010 with boost libraries. Boost comes with very > big embedding frame work and SWIG mix of C and C++ files and I don't want > to create DLLs. So, I was wondering if there is another tool to interact > python with C++ and vise versa. > > I also have an issue when I use boost. I keep getting an python version > mismatch error. I was wondering what could cause this. > > Regards, > Murat > -- Technology & Consulting Services - ned Productions Limited. http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/ -------------- next part -------------- A non-text attachment was scrubbed... Name: SMime.p7s Type: application/x-pkcs7-signature Size: 6061 bytes Desc: not available URL: From talljimbo at gmail.com Tue Aug 14 17:54:16 2012 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 14 Aug 2012 08:54:16 -0700 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> Message-ID: On Aug 14, 2012 4:25 AM, "shahmi" wrote: > > Hi, > > I have tried to access/expose 2D array from python in C++ using boost::multi_array. Nevertheless, it seems that the boost::multi_array datatype is not supported. Is there any way to resolve this? My way of accessing it as below: > > boost::python::object Vp = main_namespace["Vp"]; > Vp_cpp = boost::python::extract >(Vp); > > I've also tried to try to use 2D vector as below, nonetheless, it still doesn't work: > > boost::python::object Vp = main_namespace["Vp"]; > Vp_cpp = boost::python::extract > >(Vp); > > The error message I received is "TypeError: No registered converter was able to produce a C++ rvalue of type std::vector >, std::allocator > > > from this Python object of type matrix" > In general Boost.Python doesn't provide converters for all the other boost libraries. The first question is what you want to return in Python; you could wrap multi_array itself using class_. You could also return a nested list or tuple. If you want to use numpy, you'll probably want a helper library like this one: https://github.com/ndarray/Boost.NumPy In either of the last two cases, you can either write your own converter and add it to the converter registry (harder, but reusable), or write a custom wrapper for the function that returns a 2-d array (easier, but not good if you have many such functions). HTH Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 15 10:47:30 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 15 Aug 2012 16:47:30 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> Message-ID: <1345020450.71023.YahooMailNeo@web190606.mail.sg3.yahoo.com> Hi Jim, Do you mean, "you could wrap multi_array itself using class_", I should do as below: boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); I also did as below to expose the data from python to C++: main_namespace["Vp"] = boost::python::ptr(&Vp_cpp); However, when I try to access the data to the std::cout, like the following, it complains: std::cout << "Vp_cpp = " << Vp_cpp << std::endl; What could be wrong or am I missing something? Thanks in advance. ________________________________ From: Jim Bosch To: Development of Python/C++ integration ; shahmi Sent: Tuesday, August 14, 2012 5:54 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On Aug 14, 2012 4:25 AM, "shahmi" wrote: > > Hi, > > I have tried to access/expose 2D array from python in C++ using boost::multi_array. Nevertheless, it seems that the boost::multi_array?datatype is not supported.? Is there any way to resolve this? My way of accessing it as below: > > ? ? ? ? ? ? boost::python::object Vp = main_namespace["Vp"]; > ? ? ? ? ? ? Vp_cpp = boost::python::extract?>(Vp); > > I've also tried to try to use 2D vector as below, nonetheless, it still doesn't work: > > ??? ??? boost::python::object Vp = main_namespace["Vp"]; > ??? ??? Vp_cpp = boost::python::extract > >(Vp); > > The error message I received is "TypeError: No registered converter was able to produce a C++ rvalue of type std::vector >, std::allocator > > > from this Python object of type matrix" > In general Boost.Python doesn't provide converters for all the other boost libraries. The first question is what you want to return in Python; you could wrap multi_array itself using class_.? You could also return a nested list or tuple. If you want to use numpy, you'll probably want a helper library like this one: https://github.com/ndarray/Boost.NumPy In either of the last two cases, you can either write your own converter and add it to the converter registry (harder, but reusable), or write a custom wrapper for the function that returns a 2-d array (easier, but not good if you have many such functions). HTH Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 15 10:57:07 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 15 Aug 2012 16:57:07 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> Message-ID: <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> I apologize for double posting this because it was spammed before. Hi Jim, Do you mean, "you could wrap multi_array itself using class_", I should do as below: boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); I also did as below to expose the data from python to C++: main_namespace["Vp"] = boost::python::ptr(&Vp_cpp); However, when I try to access the data to the std::cout, like the following, it complains: std::cout << "Vp_cpp = " << Vp_cpp << std::endl; What could be wrong or am I missing something? Thanks in advance. ________________________________ From: Jim Bosch To: Development of Python/C++ integration ; shahmi Sent: Tuesday, August 14, 2012 5:54 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On Aug 14, 2012 4:25 AM, "shahmi" wrote: > > Hi, > > I have tried to access/expose 2D array from python in C++ using boost::multi_array. Nevertheless, it seems that the boost::multi_array?datatype is not supported.? Is there any way to resolve this? My way of accessing it as below: > > ? ? ? ? ? ? boost::python::object Vp = main_namespace["Vp"]; > ? ? ? ? ? ? Vp_cpp = boost::python::extract?>(Vp); > > I've also tried to try to use 2D vector as below, nonetheless, it still doesn't work: > > ??? ??? boost::python::object Vp = main_namespace["Vp"]; > ??? ??? Vp_cpp = boost::python::extract > >(Vp); > > The error message I received is "TypeError: No registered converter was able to produce a C++ rvalue of type std::vector >, std::allocator > > > from this Python object of type matrix" > In general Boost.Python doesn't provide converters for all the other boost libraries. The first question is what you want to return in Python; you could wrap multi_array itself using class_.? You could also return a nested list or tuple. If you want to use numpy, you'll probably want a helper library like this one: https://github.com/ndarray/Boost.NumPy In either of the last two cases, you can either write your own converter and add it to the converter registry (harder, but reusable), or write a custom wrapper for the function that returns a 2-d array (easier, but not good if you have many such functions). HTH Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 15 11:01:35 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 15 Aug 2012 17:01:35 +0800 (SGT) Subject: [C++-sig] Fw: Accessing 2D array from python in C++ In-Reply-To: <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> Message-ID: <1345021295.20509.YahooMailNeo@web190602.mail.sg3.yahoo.com> ----- Forwarded Message ----- From: alfa To: Jim Bosch ; Development of Python/C++ integration Sent: Wednesday, August 15, 2012 10:57 AM Subject: Re: [C++-sig] Accessing 2D array from python in C++ I apologize for double posting this because it was spammed before. Hi Jim, Do you mean, "you could wrap multi_array itself using class_", I should do as below: boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); I also did as below to expose the data from python to C++: main_namespace["Vp"] = boost::python::ptr(&Vp_cpp); However, when I try to access the data to the std::cout, like the following, it complains: std::cout << "Vp_cpp = " << Vp_cpp << std::endl; What could be wrong or am I missing something? Thanks in advance. ________________________________ From: Jim Bosch To: Development of Python/C++ integration ; shahmi Sent: Tuesday, August 14, 2012 5:54 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On Aug 14, 2012 4:25 AM, "shahmi" wrote: > > Hi, > > I have tried to access/expose 2D array from python in C++ using boost::multi_array. Nevertheless, it seems that the boost::multi_array?datatype is not supported.? Is there any way to resolve this? My way of accessing it as below: > > ? ? ? ? ? ? boost::python::object Vp = main_namespace["Vp"]; > ? ? ? ? ? ? Vp_cpp = boost::python::extract?>(Vp); > > I've also tried to try to use 2D vector as below, nonetheless, it still doesn't work: > > ??? ??? boost::python::object Vp = main_namespace["Vp"]; > ??? ??? Vp_cpp = boost::python::extract > >(Vp); > > The error message I received is "TypeError: No registered converter was able to produce a C++ rvalue of type std::vector >, std::allocator > > > from this Python object of type matrix" > In general Boost.Python doesn't provide converters for all the other boost libraries. The first question is what you want to return in Python; you could wrap multi_array itself using class_.? You could also return a nested list or tuple. If you want to use numpy, you'll probably want a helper library like this one: https://github.com/ndarray/Boost.NumPy In either of the last two cases, you can either write your own converter and add it to the converter registry (harder, but reusable), or write a custom wrapper for the function that returns a 2-d array (easier, but not good if you have many such functions). HTH Jim _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 15 15:05:17 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 15 Aug 2012 21:05:17 +0800 (SGT) Subject: [C++-sig] Problem exposing 2D python array in C++ Message-ID: <1345035917.24211.YahooMailNeo@web190604.mail.sg3.yahoo.com> Hi, Is the following way valid to expose a 2D array variable from python (Vp)? to c++(Vp_cpp)? ?? std::vector > Vp_cpp; boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); main_namespace["Vp"] = boost::python::ptr(&Vp_cpp); But, then if I tried to manipulate the 2D vector in C++ like the following, it doesn't work: Vp_cpp[1][1] = 999; std::cout << "Vp_cpp[1][1] = " << Vp_cpp[1][1] << std::endl;? // It doesn't print to What could be wrong or am I missing something? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 15 15:11:49 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 15 Aug 2012 21:11:49 +0800 (SGT) Subject: [C++-sig] Exposing 2D python array in C++ Message-ID: <1345036309.93831.YahooMailNeo@web190605.mail.sg3.yahoo.com> Hi, Is the following way valid to expose a 2D array variable from python (Vp)? to c++(Vp_cpp)? ?? std::vector > Vp_cpp; boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); main_namespace["Vp"] = boost::python::ptr(&Vp_cpp); But, then if I tried to manipulate the 2D vector in C++ like the following, it doesn't work: Vp_cpp[1][1] = 999; std::cout << "Vp_cpp[1][1] = " << Vp_cpp[1][1] << std::endl;? // It doesn't print to What could be wrong or am I missing something? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Wed Aug 15 17:34:54 2012 From: talljimbo at gmail.com (Jim Bosch) Date: Wed, 15 Aug 2012 08:34:54 -0700 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> Message-ID: On Aug 15, 2012 1:57 AM, "alfa" wrote: > > I apologize for double posting this because it was spammed before. > > Hi Jim, > > Do you mean, "you could wrap multi_array itself using class_", I should do as below: > > boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); > No, I don't think that will work; I meant something like this: boost::python::class_< boost::multi_array<...> >(...) ...; Where the last "..." is where you have to manually wrap the features of multi_array you want to use. I'm afraid there's nothing as easy as vector_indexing_suite. Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Thu Aug 16 10:29:35 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Thu, 16 Aug 2012 16:29:35 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> Message-ID: <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> Hi, Could you give more hints on this or any code snippet that I can implement this. I'm a bit naive in applying this. Please consider my 2D array of Vp_cpp(Vp equivalent in Python) is as below: ??? typedef boost::multi_array array_type; ??? typedef array_type::index index; ??? array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); I'm still puzzled how to "manually wrap the features" in the last "..." in: ??? boost::python::class_< boost::multi_array<...> >(...) Thanks in advance. ________________________________ From: Jim Bosch To: alfa Cc: Development of Python/C++ integration Sent: Wednesday, August 15, 2012 5:34 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On Aug 15, 2012 1:57 AM, "alfa" wrote: > > I apologize for double posting this because it was spammed before. > > Hi Jim, > > Do you mean, "you could wrap multi_array itself using class_", I should do as below: > > boost::python::class_ > >("PyVec").def(boost::python::vector_indexing_suite > >()); > No, I don't think that will work; I meant something like this: boost::python::class_< boost::multi_array<...> >(...) ??? ...; Where the last "..." is where you have to manually wrap the features of multi_array you want to use.? I'm afraid there's nothing as easy as vector_indexing_suite. Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Thu Aug 16 17:02:03 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Thu, 16 Aug 2012 16:02:03 +0100 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> Message-ID: If you don't mind digging around in my code, you could download the source code for the STEME python package from pypi and look in the c++/myrrh directory. There is code to access multi_arrays from python in there. http://pypi.python.org/pypi/STEME/ In particular the file c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the implementation. HTH, John. On 16/08/12 09:29, alfa wrote: > Hi, > > Could you give more hints on this or any code snippet that I can > implement this. I'm a bit naive in applying this. Please consider my 2D > array of Vp_cpp(Vp equivalent in Python) is as below: > > typedef boost::multi_array array_type; > typedef array_type::index index; > array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); > > > I'm still puzzled how to "manually wrap the features" in the last "..." in: > boost::python::class_< boost::multi_array<...> >(...) > > Thanks in advance. > > ------------------------------------------------------------------------ > *From:* Jim Bosch > *To:* alfa > *Cc:* Development of Python/C++ integration > *Sent:* Wednesday, August 15, 2012 5:34 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > On Aug 15, 2012 1:57 AM, "alfa" > wrote: >> >> I apologize for double posting this because it was spammed before. >> >> Hi Jim, >> >> Do you mean, "you could wrap multi_array itself using class_", I > should do as below: >> >> boost::python::class_ > >>("PyVec").def(boost::python::vector_indexing_suite >> >()); >> > No, I don't think that will work; I meant something like this: > boost::python::class_< boost::multi_array<...> >(...) > ...; > Where the last "..." is where you have to manually wrap the features of > multi_array you want to use. I'm afraid there's nothing as easy as > vector_indexing_suite. > Jim > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From trigves at yahoo.com Fri Aug 17 14:58:34 2012 From: trigves at yahoo.com (Trigve Siver) Date: Fri, 17 Aug 2012 05:58:34 -0700 (PDT) Subject: [C++-sig] Member function of other class Message-ID: <1345208314.56489.YahooMailNeo@web110413.mail.gq1.yahoo.com> Hi, I'm curios, why this piece of code does compile? struct?BaseClass { void?func()?{} }; struct?Wrap { void?func()?{} }; BOOST_PYTHON_MODULE(main) { class_("Base",?no_init) .def("func",?&Wrap::func) ; } I'm asking because a want to do something like this and want to know if it is UB or not: struct?BaseClass { void?func()?{} }; struct?Wrap { static?void?func(BaseClass?&Instance) { Instance.func(); } }; BOOST_PYTHON_MODULE(main) { class_("Base",?init<>()) .def("func",?&Wrap::func) ; } then in python: import?main main.Base().func() Thank you Trigve From trigves at yahoo.com Fri Aug 17 15:07:03 2012 From: trigves at yahoo.com (Trigve Siver) Date: Fri, 17 Aug 2012 06:07:03 -0700 (PDT) Subject: [C++-sig] Member function of other class In-Reply-To: <1345208314.56489.YahooMailNeo@web110413.mail.gq1.yahoo.com> References: <1345208314.56489.YahooMailNeo@web110413.mail.gq1.yahoo.com> Message-ID: <1345208823.63478.YahooMailNeo@web110402.mail.gq1.yahoo.com> Code formatting went wrong > ... > struct?BaseClass > { void?func()?{} > }; struct?Wrap > { void?func()?{} > }; BOOST_PYTHON_MODULE(main) > { class_("Base",?no_init) > .def("func",?&Wrap::func) ; > } struct?BaseClass { ? void?func()?{} }; struct?Wrap { ? void?func()?{} }; BOOST_PYTHON_MODULE(main) { ? class_("Base",?no_init) ? .def("func",?&Wrap::func) ; } ? > ... > struct?BaseClass > { void?func()?{} > }; struct?Wrap > { static?void?func(BaseClass?&Instance) { Instance.func(); } > }; BOOST_PYTHON_MODULE(main) > { class_("Base",?init<>()) > .def("func",?&Wrap::func) ; > } struct?BaseClass { ? void?func()?{} }; struct?Wrap { ? static?void?func(BaseClass?&Instance) ? { ??? Instance.func(); ? } }; BOOST_PYTHON_MODULE(main) { ? class_("Base",?init<>()) ?.def("func",?&Wrap::func) ; } > .. > import?main main.Base().func() > import?main main.Base().func() Trigve From alfarobi0161 at yahoo.com Wed Aug 22 12:13:34 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 22 Aug 2012 18:13:34 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> Message-ID: <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> Hi John, Thanks a lot for your implementation. In multi_array_to_numpy.h,? can you give more hints on which method/function that I can possibly use if I can include it in my implementation as a header file. Thanks in advance. ________________________________ From: John Reid To: cplusplus-sig at python.org Sent: Thursday, August 16, 2012 5:02 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ If you don't mind digging around in my code, you could download the source code for the STEME python package from pypi and look in the c++/myrrh directory. There is code to access multi_arrays from python in there. http://pypi.python.org/pypi/STEME/ In particular the file c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the implementation. HTH, John. On 16/08/12 09:29, alfa wrote: > Hi, > > Could you give more hints on this or any code snippet that I can > implement this. I'm a bit naive in applying this. Please consider my 2D > array of Vp_cpp(Vp equivalent in Python) is as below: > >? ? typedef boost::multi_array array_type; >? ? typedef array_type::index index; >? ? array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); > > > I'm still puzzled how to "manually wrap the features" in the last "..." in: >? ? boost::python::class_< boost::multi_array<...> >(...) > > Thanks in advance. > > ------------------------------------------------------------------------ > *From:* Jim Bosch > *To:* alfa > *Cc:* Development of Python/C++ integration > *Sent:* Wednesday, August 15, 2012 5:34 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > On Aug 15, 2012 1:57 AM, "alfa" > wrote: >> >> I apologize for double posting this because it was spammed before. >> >> Hi Jim, >> >> Do you mean, "you could wrap multi_array itself using class_", I > should do as below: >> >> boost::python::class_ > >>("PyVec").def(boost::python::vector_indexing_suite >> >()); >> > No, I don't think that will work; I meant something like this: > boost::python::class_< boost::multi_array<...> >(...) >? ? ...; > Where the last "..." is where you have to manually wrap the features of > multi_array you want to use.? I'm afraid there's nothing as easy as > vector_indexing_suite. > Jim > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Wed Aug 22 12:28:53 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 22 Aug 2012 11:28:53 +0100 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> Message-ID: On 22/08/12 11:13, alfa wrote: > Hi John, > > Thanks a lot for your implementation. In multi_array_to_numpy.h, can > you give more hints on which method/function that I can possibly use if > I can include it in my implementation as a header file. > > Thanks in advance. > src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp implement a boost.python module that exposes the multi-array classes. You have choose which data types you expose multiarrays for. HTH, John. > > ------------------------------------------------------------------------ > *From:* John Reid > *To:* cplusplus-sig at python.org > *Sent:* Thursday, August 16, 2012 5:02 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > If you don't mind digging around in my code, you could download the > source code for the STEME python package from pypi and look in the > c++/myrrh directory. There is code to access multi_arrays from python in > there. > > http://pypi.python.org/pypi/STEME/ > > In particular the file > c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the > implementation. > > HTH, > John. > > > > On 16/08/12 09:29, alfa wrote: >> Hi, >> >> Could you give more hints on this or any code snippet that I can >> implement this. I'm a bit naive in applying this. Please consider my 2D >> array of Vp_cpp(Vp equivalent in Python) is as below: >> >> typedef boost::multi_array array_type; >> typedef array_type::index index; >> array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); >> >> >> I'm still puzzled how to "manually wrap the features" in the last > "..." in: >> boost::python::class_< boost::multi_array<...> >(...) >> >> Thanks in advance. >> >> ------------------------------------------------------------------------ >> *From:* Jim Bosch > >> *To:* alfa > >> *Cc:* Development of Python/C++ integration > >> *Sent:* Wednesday, August 15, 2012 5:34 PM >> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >> >> On Aug 15, 2012 1:57 AM, "alfa" >> >> wrote: >>> >>> I apologize for double posting this because it was spammed before. >>> >>> Hi Jim, >>> >>> Do you mean, "you could wrap multi_array itself using class_", I >> should do as below: >>> >>> boost::python::class_ > >>>("PyVec").def(boost::python::vector_indexing_suite >>> >()); >>> >> No, I don't think that will work; I meant something like this: >> boost::python::class_< boost::multi_array<...> >(...) >> ...; >> Where the last "..." is where you have to manually wrap the features of >> multi_array you want to use. I'm afraid there's nothing as easy as >> vector_indexing_suite. >> Jim >> >> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From alfarobi0161 at yahoo.com Wed Aug 22 12:45:56 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 22 Aug 2012 18:45:56 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> Message-ID: <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> Hi John, I'm sorry, I'm a bit confused because previously you said that the relevant implementation resides in "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". Hope you understand my problem of having 2D array in python that needs to be exposed/converted to C++. It would be great If I know any method/function that I can invoke from any of your implementations. Thanks in advance. ________________________________ From: John Reid To: cplusplus-sig at python.org Sent: Wednesday, August 22, 2012 12:28 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On 22/08/12 11:13, alfa wrote: > Hi John, > > Thanks a lot for your implementation. In multi_array_to_numpy.h,? can > you give more hints on which method/function that I can possibly use if > I can include it in my implementation as a header file. > > Thanks in advance. > src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp implement a boost.python module that exposes the multi-array classes. You have choose which data types you expose multiarrays for. HTH, John. > > ------------------------------------------------------------------------ > *From:* John Reid > *To:* cplusplus-sig at python.org > *Sent:* Thursday, August 16, 2012 5:02 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > If you don't mind digging around in my code, you could download the > source code for the STEME python package from pypi and look in the > c++/myrrh directory. There is code to access multi_arrays from python in > there. > > http://pypi.python.org/pypi/STEME/ > > In particular the file > c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the > implementation. > > HTH, > John. > > > > On 16/08/12 09:29, alfa wrote: >> Hi, >> >> Could you give more hints on this or any code snippet that I can >> implement this. I'm a bit naive in applying this. Please consider my 2D >> array of Vp_cpp(Vp equivalent in Python) is as below: >> >>? ? typedef boost::multi_array array_type; >>? ? typedef array_type::index index; >>? ? array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); >> >> >> I'm still puzzled how to "manually wrap the features" in the last > "..." in: >>? ? boost::python::class_< boost::multi_array<...> >(...) >> >> Thanks in advance. >> >> ------------------------------------------------------------------------ >> *From:* Jim Bosch > >> *To:* alfa > >> *Cc:* Development of Python/C++ integration > >> *Sent:* Wednesday, August 15, 2012 5:34 PM >> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >> >> On Aug 15, 2012 1:57 AM, "alfa" >> >> wrote: >>> >>> I apologize for double posting this because it was spammed before. >>> >>> Hi Jim, >>> >>> Do you mean, "you could wrap multi_array itself using class_", I >> should do as below: >>> >>> boost::python::class_ > >>>("PyVec").def(boost::python::vector_indexing_suite >>> >()); >>> >> No, I don't think that will work; I meant something like this: >> boost::python::class_< boost::multi_array<...> >(...) >>? ? ...; >> Where the last "..." is where you have to manually wrap the features of >> multi_array you want to use.? I'm afraid there's nothing as easy as >> vector_indexing_suite. >> Jim >> >> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Wed Aug 22 12:58:27 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 22 Aug 2012 11:58:27 +0100 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> Message-ID: On 22/08/12 11:45, alfa wrote: > Hi John, > > I'm sorry, I'm a bit confused because previously you said that the > relevant implementation resides in > "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to > "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". > Hope you understand my problem of having 2D array in python that needs > to be exposed/converted to C++. It would be great If I know any > method/function that I can invoke from any of your implementations. > > Thanks in advance. Hi Alfa, You can look at all of the code I've mentioned to work out how it works. If it does not make sense perhaps it might be worth working through the boost.python tutorial to get up to speed on how boost.python works. You can call the expose_converters< npy_double >() function to expose multiarrays of doubles to python as numpy arrays. Please ask if you have any specific questions. Regards, John. > > > ------------------------------------------------------------------------ > *From:* John Reid > *To:* cplusplus-sig at python.org > *Sent:* Wednesday, August 22, 2012 12:28 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > On 22/08/12 11:13, alfa wrote: >> Hi John, >> >> Thanks a lot for your implementation. In multi_array_to_numpy.h, can >> you give more hints on which method/function that I can possibly use if >> I can include it in my implementation as a header file. >> >> Thanks in advance. >> > src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp > implement a boost.python module that exposes the multi-array classes. > You have choose which data types you expose multiarrays for. > > HTH, > John. > > >> >> ------------------------------------------------------------------------ >> *From:* John Reid > >> *To:* cplusplus-sig at python.org >> *Sent:* Thursday, August 16, 2012 5:02 PM >> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >> >> If you don't mind digging around in my code, you could download the >> source code for the STEME python package from pypi and look in the >> c++/myrrh directory. There is code to access multi_arrays from python in >> there. >> >> http://pypi.python.org/pypi/STEME/ >> >> In particular the file >> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the >> implementation. >> >> HTH, >> John. >> >> >> >> On 16/08/12 09:29, alfa wrote: >>> Hi, >>> >>> Could you give more hints on this or any code snippet that I can >>> implement this. I'm a bit naive in applying this. Please consider my 2D >>> array of Vp_cpp(Vp equivalent in Python) is as below: >>> >>> typedef boost::multi_array array_type; >>> typedef array_type::index index; >>> array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); >>> >>> >>> I'm still puzzled how to "manually wrap the features" in the last >> "..." in: >>> boost::python::class_< boost::multi_array<...> >(...) >>> >>> Thanks in advance. >>> >>> ------------------------------------------------------------------------ >>> *From:* Jim Bosch > >> >>> *To:* alfa > >> >>> *Cc:* Development of Python/C++ integration >> >> >>> *Sent:* Wednesday, August 15, 2012 5:34 PM >>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >>> >>> On Aug 15, 2012 1:57 AM, "alfa" >> > >>> > >>> wrote: >>>> >>>> I apologize for double posting this because it was spammed before. >>>> >>>> Hi Jim, >>>> >>>> Do you mean, "you could wrap multi_array itself using class_", I >>> should do as below: >>>> >>>> boost::python::class_ > >>>>("PyVec").def(boost::python::vector_indexing_suite >>>> >()); >>>> >>> No, I don't think that will work; I meant something like this: >>> boost::python::class_< boost::multi_array<...> >(...) >>> ...; >>> Where the last "..." is where you have to manually wrap the features of >>> multi_array you want to use. I'm afraid there's nothing as easy as >>> vector_indexing_suite. >>> Jim >>> >>> >>> >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org > > >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org > > >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From j.reid at mail.cryst.bbk.ac.uk Wed Aug 22 13:11:00 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 22 Aug 2012 12:11:00 +0100 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> Message-ID: On 22/08/12 11:58, John Reid wrote: > > > On 22/08/12 11:45, alfa wrote: >> Hi John, >> >> I'm sorry, I'm a bit confused because previously you said that the >> relevant implementation resides in >> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to >> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". >> Hope you understand my problem of having 2D array in python that needs >> to be exposed/converted to C++. It would be great If I know any >> method/function that I can invoke from any of your implementations. >> >> Thanks in advance. > > Hi Alfa, > > You can look at all of the code I've mentioned to work out how it works. > If it does not make sense perhaps it might be worth working through the > boost.python tutorial to get up to speed on how boost.python works. > > You can call the expose_converters< npy_double >() function to expose > multiarrays of doubles to python as numpy arrays. Also look in python_test/test_man.py for code that tests the implementation from the python side if it helps. From alfarobi0161 at yahoo.com Wed Aug 22 13:20:00 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 22 Aug 2012 19:20:00 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> Message-ID: <1345634400.17336.YahooMailNeo@web190604.mail.sg3.yahoo.com> Hi John, "" ________________________________ From: John Reid To: cplusplus-sig at python.org Sent: Wednesday, August 22, 2012 12:58 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ Hi John, "You can call the expose_converters< npy_double >() function to expose multiarrays of doubles to python as numpy arrays." I'm afraid you understood that I have C++ array to be exposed as? numpy arrays in Python. My problem is actually the other way around, in which I have a 2D python array/matrix that I want to convert to/access in C++. Thanks in advance. On 22/08/12 11:45, alfa wrote: > Hi John, > > I'm sorry, I'm a bit confused because previously you said that the > relevant implementation resides in > "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to > "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". > Hope you understand my problem of having 2D array in python that needs > to be exposed/converted to C++. It would be great If I know any > method/function that I can invoke from any of your implementations. > > Thanks in advance. Hi Alfa, You can look at all of the code I've mentioned to work out how it works. If it does not make sense perhaps it might be worth working through the boost.python tutorial to get up to speed on how boost.python works. You can call the expose_converters< npy_double >() function to expose multiarrays of doubles to python as numpy arrays. Please ask if you have any specific questions. Regards, John. > > > ------------------------------------------------------------------------ > *From:* John Reid > *To:* cplusplus-sig at python.org > *Sent:* Wednesday, August 22, 2012 12:28 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > On 22/08/12 11:13, alfa wrote: >> Hi John, >> >> Thanks a lot for your implementation. In multi_array_to_numpy.h,? can >> you give more hints on which method/function that I can possibly use if >> I can include it in my implementation as a header file. >> >> Thanks in advance. >> > src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp > implement a boost.python module that exposes the multi-array classes. > You have choose which data types you expose multiarrays for. > > HTH, > John. > > >> >> ------------------------------------------------------------------------ >> *From:* John Reid > >> *To:* cplusplus-sig at python.org >> *Sent:* Thursday, August 16, 2012 5:02 PM >> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >> >> If you don't mind digging around in my code, you could download the >> source code for the STEME python package from pypi and look in the >> c++/myrrh directory. There is code to access multi_arrays from python in >> there. >> >> http://pypi.python.org/pypi/STEME/ >> >> In particular the file >> c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the >> implementation. >> >> HTH, >> John. >> >> >> >> On 16/08/12 09:29, alfa wrote: >>> Hi, >>> >>> Could you give more hints on this or any code snippet that I can >>> implement this. I'm a bit naive in applying this. Please consider my 2D >>> array of Vp_cpp(Vp equivalent in Python) is as below: >>> >>>? ? typedef boost::multi_array array_type; >>>? ? typedef array_type::index index; >>>? ? array_type Vp_cpp(boost::extents[X_cpp][X_cpp]); >>> >>> >>> I'm still puzzled how to "manually wrap the features" in the last >> "..." in: >>>? ? boost::python::class_< boost::multi_array<...> >(...) >>> >>> Thanks in advance. >>> >>> ------------------------------------------------------------------------ >>> *From:* Jim Bosch > >> >>> *To:* alfa > >> >>> *Cc:* Development of Python/C++ integration >> >> >>> *Sent:* Wednesday, August 15, 2012 5:34 PM >>> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ >>> >>> On Aug 15, 2012 1:57 AM, "alfa" >> > >>> > >>> wrote: >>>> >>>> I apologize for double posting this because it was spammed before. >>>> >>>> Hi Jim, >>>> >>>> Do you mean, "you could wrap multi_array itself using class_", I >>> should do as below: >>>> >>>> boost::python::class_ > >>>>("PyVec").def(boost::python::vector_indexing_suite >>>> >()); >>>> >>> No, I don't think that will work; I meant something like this: >>> boost::python::class_< boost::multi_array<...> >(...) >>>? ? ...; >>> Where the last "..." is where you have to manually wrap the features of >>> multi_array you want to use.? I'm afraid there's nothing as easy as >>> vector_indexing_suite. >>> Jim >>> >>> >>> >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org > > >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org > > >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From alfarobi0161 at yahoo.com Wed Aug 22 13:28:18 2012 From: alfarobi0161 at yahoo.com (alfa) Date: Wed, 22 Aug 2012 19:28:18 +0800 (SGT) Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> Message-ID: <1345634898.12641.YahooMailNeo@web190603.mail.sg3.yahoo.com> Hi John, "You can call the expose_converters< npy_double >() function to expose multiarrays of doubles to python as numpy arrays." I'm afraid you understood that I have a C++ array that is to be exposed in Python. Actually, my problem is the other way around in which I have a Python array that needs to be converted to/ exposed in C++. Thanks in advance. ________________________________ From: John Reid To: cplusplus-sig at python.org Sent: Wednesday, August 22, 2012 1:11 PM Subject: Re: [C++-sig] Accessing 2D array from python in C++ On 22/08/12 11:58, John Reid wrote: > > > On 22/08/12 11:45, alfa wrote: >> Hi John, >> >> I'm sorry, I'm a bit confused because previously you said that the >> relevant implementation resides in >> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to >> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". >> Hope you understand my problem of having 2D array in python that needs >> to be exposed/converted to C++. It would be great If I know any >> method/function that I can invoke from any of your implementations. >> >> Thanks in advance. > > Hi Alfa, > > You can look at all of the code I've mentioned to work out how it works. > If it does not make sense perhaps it might be worth working through the > boost.python tutorial to get up to speed on how boost.python works. > > You can call the expose_converters< npy_double >() function to expose > multiarrays of doubles to python as numpy arrays. Also look in python_test/test_man.py for code that tests the implementation from the python side if it helps. _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Wed Aug 22 14:03:01 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 22 Aug 2012 13:03:01 +0100 Subject: [C++-sig] Accessing 2D array from python in C++ In-Reply-To: <1345634898.12641.YahooMailNeo@web190603.mail.sg3.yahoo.com> References: <1344943525.62630.YahooMailNeo@web190601.mail.sg3.yahoo.com> <1345021027.75677.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345105775.68082.YahooMailNeo@web190606.mail.sg3.yahoo.com> <1345630414.39266.YahooMailNeo@web190602.mail.sg3.yahoo.com> <1345632356.46129.YahooMailNeo@web190605.mail.sg3.yahoo.com> <1345634898.12641.YahooMailNeo@web190603.mail.sg3.yahoo.com> Message-ID: On 22/08/12 12:28, alfa wrote: > Hi John, > > "You can call the expose_converters< npy_double >() function to expose > multiarrays of doubles to python as numpy arrays." > > I'm afraid you understood that I have a C++ array that is to be exposed > in Python. Actually, my problem is the other way around in which I have > a Python array that needs to be converted to/ exposed in C++. Exposing works both ways. > > Thanks in advance. > > > ------------------------------------------------------------------------ > *From:* John Reid > *To:* cplusplus-sig at python.org > *Sent:* Wednesday, August 22, 2012 1:11 PM > *Subject:* Re: [C++-sig] Accessing 2D array from python in C++ > > > > On 22/08/12 11:58, John Reid wrote: >> >> >> On 22/08/12 11:45, alfa wrote: >>> Hi John, >>> >>> I'm sorry, I'm a bit confused because previously you said that the >>> relevant implementation resides in >>> "c++/myrrh/myrrh/python/multi_array_to_numpy.h"but now, you point to >>> "src/python/man_module.cpp and src/python/multi_array_to_numpy.cpp". >>> Hope you understand my problem of having 2D array in python that needs >>> to be exposed/converted to C++. It would be great If I know any >>> method/function that I can invoke from any of your implementations. >>> >>> Thanks in advance. >> >> Hi Alfa, >> >> You can look at all of the code I've mentioned to wor k out how it works. >> If it does not make sense perhaps it might be worth working through the >> boost.python tutorial to get up to speed on how boost.python works. >> >> You can call the expose_converters< npy_double >() function to expose >> multiarrays of doubles to python as numpy arrays. > > Also look in python_test/test_man.py for code that tests the > implementation from the python side if it helps. > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From herzog at mpi-cbg.de Thu Aug 23 16:53:55 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Thu, 23 Aug 2012 16:53:55 +0200 Subject: [C++-sig] issues with loading the boost_python dll on different computers Message-ID: Dear all, I installed and used boost (1.50.0) to build a python extension on my Windows 7 / 32 Bit. Everything worked fine. Now I tried the extension module on other Computers with Windows 7 and Windows XP and the same Python version and it gave me an error concerning the DLL: ** ImportError : DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. ** Would anyone have a hint on were this problem could come from. I am totally clueless. Thanks a lot, Ronny From trigves at yahoo.com Thu Aug 23 18:50:12 2012 From: trigves at yahoo.com (Trigve Siver) Date: Thu, 23 Aug 2012 09:50:12 -0700 (PDT) Subject: [C++-sig] issues with loading the boost_python dll on different computers In-Reply-To: References: Message-ID: <1345740612.35396.YahooMailNeo@web110413.mail.gq1.yahoo.com> > From: Ronny Herzog > To: cplusplus-sig at python.org > Cc: > Sent: Thursday, August 23, 2012 4:53 PM > Subject: [C++-sig] issues with loading the boost_python dll on different computers > > Dear all, > > I installed and used boost (1.50.0) to build a python extension on my Windows 7 > / 32 Bit. Everything worked fine. > > Now I tried the extension module on other Computers with Windows 7 and Windows > XP and the same Python version and it gave me an error concerning the DLL: > > ** ImportError : DLL load failed: This application has failed to start > because the application configuration is incorrect. Reinstalling the > application may fix this problem. ** > > Would anyone have a hint on were this problem could come from. I am totally > clueless. Hi, two possible reason from top of my mind: * Is it possible that you are using debug version of your extension? * If you are using VS, have you installed VC redist of *your's VS version* on target PC? Also try depends.exe to find if you aren't missing any dependencies. ? > Thanks a lot, > Ronny Trigve From herzog at mpi-cbg.de Fri Aug 24 14:27:35 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Fri, 24 Aug 2012 14:27:35 +0200 Subject: [C++-sig] issues with loading the boost_python dll on different computers In-Reply-To: <1345740612.35396.YahooMailNeo@web110413.mail.gq1.yahoo.com> References: <1345740612.35396.YahooMailNeo@web110413.mail.gq1.yahoo.com> Message-ID: Thanks Trigve, I used depends.exe and found out that it was looking for the debug version of the msvc runtime library. Compiling my extension in 'release' mode - everything worked. :-) Ronny Am 8/23/2012 6:50 PM, schrieb Trigve Siver: >> From: Ronny Herzog >> To: cplusplus-sig at python.org >> Cc: >> Sent: Thursday, August 23, 2012 4:53 PM >> Subject: [C++-sig] issues with loading the boost_python dll on different computers >> >> Dear all, >> >> I installed and used boost (1.50.0) to build a python extension on my Windows 7 >> / 32 Bit. Everything worked fine. >> >> Now I tried the extension module on other Computers with Windows 7 and Windows >> XP and the same Python version and it gave me an error concerning the DLL: >> >> ** ImportError : DLL load failed: This application has failed to start >> because the application configuration is incorrect. Reinstalling the >> application may fix this problem. ** >> >> Would anyone have a hint on were this problem could come from. I am totally >> clueless. > > Hi, two possible reason from top of my mind: > > * Is it possible that you are using debug version of your extension? > * If you are using VS, have you installed VC redist of *your's VS version* on target PC? > > Also try depends.exe to find if you aren't missing any dependencies. > >> Thanks a lot, >> Ronny > > Trigve > From herzog at mpi-cbg.de Fri Aug 24 14:31:19 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Fri, 24 Aug 2012 14:31:19 +0200 Subject: [C++-sig] building 32 Bit and 64 Bit extensions on the same machine Message-ID: Dear all, I want to build 32 bit extensions and 64 bit extensions on my Windows 7 / 32 Bit with boost. After two days of checking google I am a bit frustrated. I am new to Boost and it is a bit like a jungle. Can anyone help on what I need to do to set up Boost in the right way and have a Jamroot which allows me to compile my Python extensions in 32 Bit and 64 Bit at the same time (with MSVC 2008). Thanks a lot, Ronny From wmamrak at gmail.com Fri Aug 24 16:49:03 2012 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Fri, 24 Aug 2012 16:49:03 +0200 Subject: [C++-sig] building 32 Bit and 64 Bit extensions on the same machine In-Reply-To: References: Message-ID: Hi, add address-model=64 to Boost::Python bjam compilation command and that's all. Be aware, that not all MSVS versions (e.g. Express Edition) are equipped with 64 Bit compiler. 2012/8/24 Ronny Herzog : > Dear all, > > I want to build 32 bit extensions and 64 bit extensions on my Windows 7 / 32 > Bit with boost. After two days of checking google I am a bit frustrated. I > am new to Boost and it is a bit like a jungle. > > Can anyone help on what I need to do to set up Boost in the right way and > have a Jamroot which allows me to compile my Python extensions in 32 Bit and > 64 Bit at the same time (with MSVC 2008). > > Thanks a lot, > Ronny > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From hesam.ilati2 at gmail.com Fri Aug 24 17:32:11 2012 From: hesam.ilati2 at gmail.com (Hesam) Date: Fri, 24 Aug 2012 11:32:11 -0400 Subject: [C++-sig] Boost::Python and Functions with String Inputs Message-ID: *Dear Sirs,* *Goal:* I'm trying to use python interactively in my c++ code using Boost::Python library. My goal is to change variables of some class which I have defined in c++ from the python interpreter. The code is attached below. Actually this comes from Boost::Python tutorials http://www.boost.org/doc/libs/1_51_0/libs/python/doc/tutorial/doc/html/python/exposing.html *Problem:* I can load the library in python interface (i.e. load hello) and make an object out of it (obj = hello.World()). I even can access functions ( obj.greet() ) but when I want to access functions with string input (obj.set("Hello") ) I get memory access violation ("Access violation reading location 0xffffffffffffffff"). *The problem is just with string inputs. i.e. if I change function set(string) to set(char*) it works fine. * If instead of interpreter I use PyRun_SimpleString("import hello; w=hello.World(); w.set('Hi there');\n"); I get error "Expression _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)". The point is when I make breakpoint inside the function value of string is not what I want. *Details*: Visual studio 2010 (MDd mode), Debug Mode, x64, Win7 struct World { void set(string _msg) {} string greet() { return msg; } string msg; }; typedef boost::shared_ptr World_ptr; BOOST_PYTHON_MODULE(hello) { bp::class_("World") .def("greet", &World::greet) .def("set", &World::set) ; } int main(int argc, char **argv) { Py_Initialize(); bp::object main = bp::object(bp::handle<>(bp::borrowed(PyImport_AddModule("__main__")))); bp::object global(main.attr("__dict__")); inithello(); // Bring up Python interpreter Py_Main(argc, argv); Py_Finalize(); return 0; } Actually this comes from Boost::Python tutorials with some modification to use Python interpreter http://www.boost.org/doc/libs/1_51_0/libs/python/doc/tutorial/doc/html/python/exposing.html Many thanks [image: Inline image 1] -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 42055 bytes Desc: not available URL: From wmamrak at gmail.com Sun Aug 26 13:56:27 2012 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Sun, 26 Aug 2012 13:56:27 +0200 Subject: [C++-sig] building 32 Bit and 64 Bit extensions on the same machine Message-ID: 27156 From hesam.ilati2 at gmail.com Sun Aug 26 13:56:28 2012 From: hesam.ilati2 at gmail.com (Hesam) Date: Sun, 26 Aug 2012 13:56:28 +0200 Subject: [C++-sig] Boost::Python and Functions with String Inputs Message-ID: 27157 From brandsmeier at gmx.de Sun Aug 26 22:04:07 2012 From: brandsmeier at gmx.de (Holger Brandsmeier) Date: Sun, 26 Aug 2012 22:04:07 +0200 Subject: [C++-sig] `cout << tuple` is ambiguous Message-ID: Dear list, I get the following error error: use of overloaded operator '<<' is ambiguous (with operand types 'basic_ostream >' and 'const boost::python::tuple') The two candidates are an output operator for tuple, which I want to use /usr/include/boost-1_48/boost/python/object_operators.hpp:105:1: note: candidate function [with L = std::basic_ostream, R = boost::python::tuple] BOOST_PYTHON_BINARY_OPERATOR(<<) /usr/include/boost-1_48/boost/python/object_operators.hpp:90:36: note: expanded from macro 'BOOST_PYTHON_BINARY_OPERATOR' BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \ And an output operator for bools /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/ostream:172:7: note: candidate function operator<<(bool __n) How do I avoid this ambiguity with booleans? And how can I output tuples? Btw. the compiler that I used is `clang version 3.1 (trunk 154212)` Best regards, Holger Brandsmeier From herzog at mpi-cbg.de Mon Aug 27 16:23:14 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Mon, 27 Aug 2012 16:23:14 +0200 Subject: [C++-sig] building 32 Bit and 64 Bit extensions on the same machine In-Reply-To: References: Message-ID: Thank you, but this does not seem to work. If I do this with "bjam --address-model=64 -n" I can see that it does compile it with my 32Bit Python and without setting the x86_AMD64 flag: "[...] file C:\boost_1_50_0\bin.v2\libs\python\build\msvc-9.0\release\threading-multi\o bject\iterator.obj.rsp "C:\boost_1_50_0\libs\python\src\object\iterator.cpp" -Fo"C:\boost_1_50_0\bin.v2 \libs\python\build\msvc-9.0\release\threading-multi\object\iterator.obj" -TP /O2 /Ob2 /W3 /GR /MD /Zc:forScope /Zc:wchar_t /wd4675 /EHs -c -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -DNDEBUG "-IC:\Python26\include" "-IC:\boost_1_50_0" compile-c-c++ C:\boost_1_50_0\bin.v2\libs\python\build\msvc-9.0\release\threadin g-multi\object\iterator.obj call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nu l cl /Zm800 -nologo @"C:\boost_1_50_0\bin.v2\libs\python\build\msvc-9.0\release\th reading-multi\object\iterator.obj.rsp" [...]" I am using MS Visual Studio 2008. Unfortunately, I cannot test it on an 64Bit machine right now. I have Python26 (32Bit) and Python26 (64Bit) installed and I guess I have to inform bjam somewhere which one to use. Thanks a lot, Ronny Am 8/24/2012 4:49 PM, schrieb Wojciech Mamrak: > Hi, > > add address-model=64 to Boost::Python bjam compilation command and > that's all. Be aware, that not all MSVS versions (e.g. Express > Edition) are equipped with 64 Bit compiler. > > 2012/8/24 Ronny Herzog : >> Dear all, >> >> I want to build 32 bit extensions and 64 bit extensions on my Windows 7 / 32 >> Bit with boost. After two days of checking google I am a bit frustrated. I >> am new to Boost and it is a bit like a jungle. >> >> Can anyone help on what I need to do to set up Boost in the right way and >> have a Jamroot which allows me to compile my Python extensions in 32 Bit and >> 64 Bit at the same time (with MSVC 2008). >> >> Thanks a lot, >> Ronny >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig From phil at philipdunstan.com Fri Aug 31 03:00:24 2012 From: phil at philipdunstan.com (Philip Dunstan) Date: Fri, 31 Aug 2012 03:00:24 +0200 Subject: [C++-sig] boost-python: Passing an object held in a boost::shared_ptr from C++ to python to C++ Message-ID: Hi I have some code that creates an object in a shared_ptr in C++. The object is then used within python and passed from Python to another C++ function that tries to keep hold of it. It appears that when the object goes from C++ to Python it is converted from a shared_ptr into a python object. Then when it goes back into C++ it is converted from the python object into a new shared_ptr, however this shared_ptr is unrelated to the initial holding shared_ptr. Is it possible to set up the boost-python bindings so that the conversion from python object to shared_ptr references the original shared_ptr internals? Below is the abridged code I have used to show the problem. I have attached the full reproducible to this email. In this example an object is initially held in a shared_ptr named s_iniital. It is grabbed from within python through the getSharedPtr function, then pushed back into C++ through the putSharedPtr function. Inside putSharedPtr it is copied into the weak_ptr s_copied. Inspecting the pointers in the debugger shows that the shared_ptr used in putSharedPtr does not have the same reference counting internals as s_initial. The final assert will fire because the weak pointer s_copied was only related to a single strong pointer (the pointer used in putSharedPtr) and that pointer was destructed once putSharedPtr was finished. static shared_ptr s_initial; static weak_ptr s_copied; class UseSharedPtr { public: shared_ptr getSharedPtr() { return s_initial; } void putSharedPtr(shared_ptr ptr) { s_copied = ptr; } }; BOOST_PYTHON_MODULE(test) { class_, boost::noncopyable>("Captured", no_init); class_("UseSharedPtr", init<>()) .def("getSharedPtr", &UseSharedPtr::getSharedPtr) .def("putSharedPtr", &UseSharedPtr::putSharedPtr) ; } s_initial = make_shared(); const char* chunk = "\ from test import UseSharedPtr \n\ x = UseSharedPtr() \n\ ptr = x.getSharedPtr() \n\ x.putSharedPtr(ptr)\n\ del x \n\ del ptr \n\ "; object result = exec(chunk, mainNamespace, mainNamespace); assert(s_copied.lock()); thanks, Phil -- Philip Dunstan phil at philipdunstan.com www.philipdunstan.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: test.cpp Type: text/x-c++src Size: 1862 bytes Desc: not available URL: From zao at acc.umu.se Fri Aug 31 03:34:10 2012 From: zao at acc.umu.se (Lars Viklund) Date: Fri, 31 Aug 2012 03:34:10 +0200 Subject: [C++-sig] building 32 Bit and 64 Bit extensions on the same machine In-Reply-To: References: Message-ID: <20120831013410.GK622624@lenin.acc.umu.se> On Mon, Aug 27, 2012 at 04:23:14PM +0200, Ronny Herzog wrote: > Thank you, > > but this does not seem to work. If I do this with > "bjam --address-model=64 -n" Note that the previous poster did not say "--address-model=64". He said "address-model=64". It's a feature, not an option. Features do not have a leading dashdash. You may of course have to point out a suitable Python path anyway, but it helps if you actually instruct the build to be 64-bit in the first place. -- Lars Viklund | zao at acc.umu.se From brandsmeier at gmx.de Fri Aug 31 10:09:36 2012 From: brandsmeier at gmx.de (Holger Brandsmeier) Date: Fri, 31 Aug 2012 10:09:36 +0200 Subject: [C++-sig] boost-python: Passing an object held in a boost::shared_ptr from C++ to python to C++ In-Reply-To: References: Message-ID: Dear Phil, the problem you are phasing is because you use a weak pointer. I had a very similar problem in April, you may read it up here http://mail.python.org/pipermail/cplusplus-sig/2012-April/016524.html There I also tried to explain why this happens, I'm not sure if I did a good job, just ask. To be able to help you here, can you explain a little bit more about your usecase? In my case I was able to exploit that the weak_ptr that I needed to access, was a pointer to the class itself. And I only ran into trouble, that I wanted to call an unsafe function like your `putSharedPtr` from python, when I extended this class from python. Whenever I needed to use `s_copied` I call a function, say `getPointer()`, that in pure C++ would just turn `s_copied` from weak_ptr into shared_ptr. In python extended classes I implement `getPointer()` not in terms of `s_copied`, but by just returning `self`. -Holger On Fri, Aug 31, 2012 at 3:00 AM, Philip Dunstan wrote: > Hi > > I have some code that creates an object in a shared_ptr in C++. The object > is then used within python and passed from Python to another C++ function > that tries to keep hold of it. It appears that when the object goes from C++ > to Python it is converted from a shared_ptr into a python object. Then > when it goes back into C++ it is converted from the python object into a new > shared_ptr, however this shared_ptr is unrelated to the initial holding > shared_ptr. > > Is it possible to set up the boost-python bindings so that the conversion > from python object to shared_ptr references the original shared_ptr > internals? > > Below is the abridged code I have used to show the problem. I have attached > the full reproducible to this email. In this example an object is initially > held in a shared_ptr named s_iniital. It is grabbed from within python > through the getSharedPtr function, then pushed back into C++ through the > putSharedPtr function. Inside putSharedPtr it is copied into the weak_ptr > s_copied. Inspecting the pointers in the debugger shows that the shared_ptr > used in putSharedPtr does not have the same reference counting internals as > s_initial. The final assert will fire because the weak pointer s_copied was > only related to a single strong pointer (the pointer used in putSharedPtr) > and that pointer was destructed once putSharedPtr was finished. > > > static shared_ptr s_initial; > static weak_ptr s_copied; > > class UseSharedPtr > { > public: > shared_ptr getSharedPtr() > { > return s_initial; > } > > void putSharedPtr(shared_ptr ptr) > { > s_copied = ptr; > } > }; > > > BOOST_PYTHON_MODULE(test) > { > class_, boost::noncopyable>("Captured", > no_init); > class_("UseSharedPtr", init<>()) > .def("getSharedPtr", &UseSharedPtr::getSharedPtr) > .def("putSharedPtr", &UseSharedPtr::putSharedPtr) > ; > } > > > > s_initial = make_shared(); > > const char* chunk = "\ > from test import UseSharedPtr \n\ > x = UseSharedPtr() \n\ > ptr = x.getSharedPtr() \n\ > x.putSharedPtr(ptr)\n\ > del x \n\ > del ptr \n\ > "; > object result = exec(chunk, mainNamespace, mainNamespace); > > assert(s_copied.lock()); > > > > thanks, > Phil > -- > Philip Dunstan > phil at philipdunstan.com > www.philipdunstan.com > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig