From rwgk at yahoo.com Thu Oct 1 06:48:19 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Wed, 30 Sep 2009 21:48:19 -0700 (PDT) Subject: [C++-sig] boost python to/from python type conversion In-Reply-To: <4AC3D04D.805@fnal.gov> References: <4AC3D04D.805@fnal.gov> Message-ID: <440430.92877.qm@web111406.mail.gq1.yahoo.com> lvalue_from_pytype only works for passing by value or const references/pointers, but that seems to match your case, since you MPI_Comm is passed by value to your sayhello(). However, wrapping extern "C" isn't portable, AFAIK. You'll need a thin C++ wrapper for each of the C functions. Did you consider writing a thin object-oriented wrapper around the raw MPI interfaces? Then it should be very straightforward to bind the wrapper with Boost.Python, and you'll have a more intuitive Python interface. E.g. make a class that owns MPI_Comm, passed as boost::python::object, and then give it a .sayhello() method using the comm data member. ----- Original Message ---- From: James Amundson To: cplusplus-sig at python.org Sent: Wednesday, September 30, 2009 2:40:29 PM Subject: [C++-sig] boost python to/from python type conversion Hi, I'm trying to write to/from type converters for my code, and I'm stuck. My case doesn't map well to any of those in the boost python documentation. I'm trying to pass objects of type MPI_Comm (really a C type!) back and forth with mpi4py (which uses cython internally.) The mpi4py author has provided a working example using manual wrapping. I am attaching it to the end of this message. On the C++ side I can extract a point to the MPI_Comm object from a Python object like so: PyObject* py_obj; // obviously, the value of py_obj has to be set somewhere... MPI_Comm *comm_p = PyMPIComm_Get(py_obj); I thought it would be simple to write a type converter to do that, but I don't understand the mechanics. This example doesn't seem to map onto the lvalue_from_pytype paradigm, or the scitbx container_conversion paradigm. Any suggestions? Thanks, Jim Amundson ----------------------------------- // working example with manual conversion #include #include static void sayhello(MPI_Comm comm) { if (comm == MPI_COMM_NULL) { std::cout << "You passed MPI_COMM_NULL !!!" << std::endl; return; } int size; MPI_Comm_size(comm, &size); int rank; MPI_Comm_rank(comm, &rank); int plen; char pname[MPI_MAX_PROCESSOR_NAME]; MPI_Get_processor_name(pname, &plen); std::cout << "Hello, World! " << "I am process " << rank << " of " << size << " on " << pname << "." << std::endl; } #include #include using namespace boost::python; static void hw_sayhello(object py_comm) { PyObject* py_obj = py_comm.ptr(); MPI_Comm *comm_p = PyMPIComm_Get(py_obj); if (comm_p == NULL) throw_error_already_set(); sayhello(*comm_p); } BOOST_PYTHON_MODULE(helloworld) { if (import_mpi4py() < 0) return; /* Python 2.X */ def("sayhello", hw_sayhello); } _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From roman.yakovenko at gmail.com Thu Oct 1 07:04:57 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 1 Oct 2009 07:04:57 +0200 Subject: [C++-sig] [Py++] Does pyplusplus respect explicit constructors? In-Reply-To: References: Message-ID: <7465b6170909302204l4ee75231g96bc7db0da0cbb0a@mail.gmail.com> On Wed, Sep 30, 2009 at 6:18 PM, Christopher Bruns wrote: > Single-argument C++ constructors in pyplusplus seem to generate a > boost::python::implicitly_convertible tag, even when the constructor > is declared "explicit" in C++. ?That doesn't sound right to me. I don't completely agree with you. > Shouldn't a pair of types that are not implicitly convertible in C++, > also not be implicitly convertible in python? It depends on your use cases. > I suspect I can manually adjust the implicitly_convertible tag > generation using the "allow_implicit_conversion" flag in pyplusplus. > Is there a way to tell pyplusplus to avoid generating an > implicitly_convertible tag for all explicit constructors? I don't think so. I attached gccxml generated file for your code. As you can see both constructors ( Foo and Bar ) have "explitic=1". So Py++ has no way to find out whether a constructor explicit or not. If such functionality would present, I think that the default would be the opposite. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: 1.tar.bz Type: application/x-bzip Size: 4553 bytes Desc: not available URL: From austin.bingham at gmail.com Thu Oct 1 08:22:13 2009 From: austin.bingham at gmail.com (Austin Bingham) Date: Thu, 1 Oct 2009 08:22:13 +0200 Subject: [C++-sig] boost python to/from python type conversion In-Reply-To: <4AC3D04D.805@fnal.gov> References: <4AC3D04D.805@fnal.gov> Message-ID: If it's any help, I wrote a small bit on the details of writing converters. It might help clarify some of the mechanics which, I agree, are a bit mysterious: http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ Austin On Wed, Sep 30, 2009 at 11:40 PM, James Amundson wrote: > Hi, > > I'm trying to write to/from type converters for my code, and I'm stuck. My > case doesn't map well to any of those in the boost python documentation. I'm > trying to pass objects of type MPI_Comm (really a C type!) back and forth > with mpi4py (which uses cython internally.) The mpi4py author has provided a > working example using manual wrapping. I am attaching it to the end of this > message. On the C++ side I can extract a point to the MPI_Comm object from a > Python object like so: > > PyObject* py_obj; > // obviously, the value of py_obj has to be set somewhere... > MPI_Comm *comm_p = PyMPIComm_Get(py_obj); > > I thought it would be simple to write a type converter to do that, but I > don't understand the mechanics. This example doesn't seem to map onto the > lvalue_from_pytype paradigm, or the scitbx container_conversion paradigm. > > Any suggestions? > > Thanks, > Jim Amundson > > ----------------------------------- > // working example with manual conversion > > #include > #include > > static void sayhello(MPI_Comm comm) > { > ?if (comm == MPI_COMM_NULL) { > ? ?std::cout << "You passed MPI_COMM_NULL !!!" << std::endl; > ? ?return; > ?} > ?int size; > ?MPI_Comm_size(comm, &size); > ?int rank; > ?MPI_Comm_rank(comm, &rank); > ?int plen; char pname[MPI_MAX_PROCESSOR_NAME]; > ?MPI_Get_processor_name(pname, &plen); > ?std::cout << > ? ?"Hello, World! " << > ? ?"I am process " << rank << > ? ?" of " << size << > ? ?" on ?" << pname << > ? ?"." << std::endl; > } > > > #include > #include > using namespace boost::python; > > static void hw_sayhello(object py_comm) > { > ?PyObject* py_obj = py_comm.ptr(); > ?MPI_Comm *comm_p = PyMPIComm_Get(py_obj); > ?if (comm_p == NULL) throw_error_already_set(); > ?sayhello(*comm_p); > } > > BOOST_PYTHON_MODULE(helloworld) > { > ?if (import_mpi4py() < 0) return; /* Python 2.X */ > > ?def("sayhello", hw_sayhello); > } > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From cmbruns at stanford.edu Thu Oct 1 17:46:13 2009 From: cmbruns at stanford.edu (Christopher Bruns) Date: Thu, 1 Oct 2009 08:46:13 -0700 Subject: [C++-sig] [Py++] Does pyplusplus respect explicit constructors? Message-ID: Roman Yakovenko wrote: > On Wed, Sep 30, 2009 at 6:18 PM, Christopher Bruns wrote: > > I suspect I can manually adjust the implicitly_convertible tag > > generation using the "allow_implicit_conversion" flag in pyplusplus. > > Is there a way to tell pyplusplus to avoid generating an > > implicitly_convertible tag for all explicit constructors? > > I don't think so. I attached gccxml generated file for your code. As > you can see both constructors ( Foo and Bar ) have "explitic=1". So > Py++ has no way to find out whether a constructor explicit or not. I disagree. Py++ does have a way to find out. The only time "explicit" matters is when a constructor takes exactly one argument. gccxml sets "explicit=1" in all cases when the number of arguments is other than 1. That is why you saw "explicit=1" in all of the constructors in the previous example. However, in the case where there is exactly one argument, gccxml does the right thing. Consider the following case: ### test.h #### struct Foo1 {}; struct Foo2 {}; struct Bar { explicit Bar(Foo1&); // no implicit conversion Bar(Foo2&); // allows implicit conversion }; ############# ### fragment of resulting xml file from gccxml ### ####################### Notice that gccxml sets "explicit=1" for the first Bar constructor, but not for the second. However, Py++ sets "allow_implicit_conversion" to True for both constructors. I think gccxml is doing the right thing here. But I am not so sure about Py++ behavior. I would have assumed that the first Bar constructor would have "allow_implicit_conversion" set to False. I was wrong about being able to use "allow_implicit_conversion" for this task. Is there another way to get at the "explicit" xml tag from the module_builder object? Or do I need to parse the xml file or source code separately to discover this information? Thank you Roman for your diligent feedback. I sincerely appreciate the quick and thoughtful feedback you provide to everyone on this mailing list. Chris Bruns From amundson at fnal.gov Thu Oct 1 23:30:01 2009 From: amundson at fnal.gov (James Amundson) Date: Thu, 01 Oct 2009 16:30:01 -0500 Subject: [C++-sig] boost python to/from python type conversion In-Reply-To: <440430.92877.qm@web111406.mail.gq1.yahoo.com> References: <4AC3D04D.805@fnal.gov> <440430.92877.qm@web111406.mail.gq1.yahoo.com> Message-ID: <4AC51F59.40303@fnal.gov> On 09/30/2009 11:48 PM, Ralf W. Grosse-Kunstleve wrote: > lvalue_from_pytype only works for passing by value or const references/pointers, but that seems to match your case, > since you MPI_Comm is passed by value to your sayhello(). > > However, wrapping extern "C" isn't portable, AFAIK. You'll need a thin C++ wrapper for each of the C functions. > Yes. I think you are right. I'm going to try that now. > Did you consider writing a thin object-oriented wrapper around the raw MPI interfaces? Then it should be very straightforward to bind the wrapper with Boost.Python, and you'll have a more intuitive Python interface. > E.g. make a class that owns MPI_Comm, passed as boost::python::object, and then give it a .sayhello() method using the comm data member. > It's more complicated than that. mpi4py provides a nice object-oriented wrapper on the Python side. The mpi4py wrapper is based on the "standard" MPI C++ bindings. Unfortunately, older versions of MPI don't support the C++ bindings and MPI has decided that the bindings will be dropped in the future, so I really don't want to start using them now. I think I will do as you suggest and just write very thin wrappers around the C interfaces. Thanks for your help. --Jim Amundson From amundson at fnal.gov Thu Oct 1 23:30:51 2009 From: amundson at fnal.gov (James Amundson) Date: Thu, 01 Oct 2009 16:30:51 -0500 Subject: [C++-sig] boost python to/from python type conversion In-Reply-To: References: <4AC3D04D.805@fnal.gov> Message-ID: <4AC51F8B.4000907@fnal.gov> On 10/01/2009 01:22 AM, Austin Bingham wrote: > If it's any help, I wrote a small bit on the details of writing > converters. It might help clarify some of the mechanics which, I > agree, are a bit mysterious: > > http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ > > Wonderful. Your blog post is very helpful. I wish you had written it (and I had found it!) a long time ago. Thanks, Jim Amundson From roman.yakovenko at gmail.com Fri Oct 2 01:10:17 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 2 Oct 2009 01:10:17 +0200 Subject: [C++-sig] [Py++] Does pyplusplus respect explicit constructors? In-Reply-To: References: Message-ID: <7465b6170910011610r2781c0bdw4ec1e4c0fc5622d7@mail.gmail.com> On Thu, Oct 1, 2009 at 5:46 PM, Christopher Bruns wrote: > I disagree. ?Py++ does have a way to find out. ?The only time > "explicit" matters is when a constructor takes exactly one argument. > gccxml sets "explicit=1" in all cases when the number of arguments is > other than 1. ?That is why you saw "explicit=1" in all of the > constructors in the previous example. ?However, in the case where > there is exactly one argument, gccxml does the right thing. ?Consider > the following case: > > ### test.h #### > struct Foo1 {}; > struct Foo2 {}; > > struct Bar { > ? ?explicit Bar(Foo1&); // no implicit conversion > ? ?Bar(Foo2&); // allows implicit conversion > }; > ############# > > > ### fragment of resulting xml file from gccxml ### > ? access="public" mangled="_ZN3BarC1ER4Foo1 *INTERNAL* " > demangled="Bar::Bar(Foo1&)" location="f0:5" file="f0" line="5" > extern="1"> > ? ? > ? > ? mangled="_ZN3BarC1ER4Foo2 *INTERNAL* " demangled="Bar::Bar(Foo2&)" > location="f0:6" file="f0" line="6" extern="1"> > ? ? > ? > ####################### > > Notice that gccxml sets "explicit=1" for the first Bar constructor, > but not for the second. I didn't know that, so pygccxml didn't provided access to the information. > However, Py++ sets "allow_implicit_conversion" to True for both > constructors. ?I think gccxml is doing the right thing here. ?But I am > not so sure about Py++ behavior. Well, these days I would implement "allow_implicit_conversion" to be a mix of the user desire and "explicit" attribute. But, this change will introduce backward compatibility problem, which I would like to avoid. > I would have assumed that the first > Bar constructor would have "allow_implicit_conversion" set to False. > I was wrong about being able to use "allow_implicit_conversion" for > this task. ?Is there another way to get at the "explicit" xml tag from > the module_builder object? ?Or do I need to parse the xml file or > source code separately to discover this information? No. I updated pygccxml package http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1761&view=rev All you need is to write the following code: mb = module_builder_t(...) mb.constructors( lambda c: c.explicit == True ).allow_implicit_conversion = False That's all > Thank you Roman for your diligent feedback. ?I sincerely appreciate > the quick and thoughtful feedback you provide to everyone on this > mailing list. Wow :-). Thank you for such words! -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From micdestefano at gmail.com Fri Oct 2 16:06:57 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Fri, 2 Oct 2009 16:06:57 +0200 Subject: [C++-sig] Conversion from Python to C++ Message-ID: Hello to everybody. I was wondering if there is a general way to convert a C++ class wrapped in Python into a C++ class not wrapped in Python. I've not fully understood the documentation on this point. For example, assume we have two C++ classes, A and B. A is exported to Python with class_<>, while B is not exported to Python. Assume also that, in C++, A is convertible to B (i.e. I can construct a B object from an existing A object). Assume I have a C++ function (f) which takes a B object as input and I want to expose this function, but I don't want to expose the B class. Is there a general way to create a converter from A to B in order to be able to call f(A) from Python ? Thank you in advance. -- Michele De Stefano From seefeld at sympatico.ca Fri Oct 2 16:22:36 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 02 Oct 2009 10:22:36 -0400 Subject: [C++-sig] Conversion from Python to C++ In-Reply-To: References: Message-ID: <4AC60CAC.4050907@sympatico.ca> On 10/02/2009 10:06 AM, Michele De Stefano wrote: > For example, assume we have two C++ classes, A and B. A is exported to > Python with class_<>, while B is not exported to Python. > Assume also that, in C++, A is convertible to B (i.e. I can construct > a B object from an existing A object). > > Assume I have a C++ function (f) which takes a B object as input and I > want to expose this function, but I don't want to expose the B class. > > Is there a general way to create a converter from A to B in order to > be able to call f(A) from Python ? > Depending on how many such functions you have, you may either simply write a wrapper function with the right signature (i.e. accepting an 'A' and (implicitly) converting that to a 'B' when calling the actual function), or you may write a custom from_python converter. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From micdestefano at gmail.com Fri Oct 2 16:35:50 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Fri, 2 Oct 2009 16:35:50 +0200 Subject: [C++-sig] Conversion from Python to C++ In-Reply-To: <4AC60CAC.4050907@sympatico.ca> References: <4AC60CAC.4050907@sympatico.ca> Message-ID: Ok. I'd like to write a custom from_python converter, but the point is that I've not understood how it works. The explanation in the FAQs it's too obscure for me. 2009/10/2 Stefan Seefeld : > On 10/02/2009 10:06 AM, Michele De Stefano wrote: >> >> For example, assume we have two C++ classes, A and B. A is exported to >> Python with class_<>, while B is not exported to Python. >> Assume also that, in C++, A is convertible to B (i.e. I can construct >> a B object from an existing A object). >> >> Assume I have a C++ function (f) which takes a B object as input and I >> want to expose this function, but I don't want to expose the B class. >> >> Is there a general way to create a converter from A to B in order to >> be able to call f(A) from Python ? >> > > Depending on how many such functions you have, you may either simply write a > wrapper function with the right signature (i.e. accepting an 'A' and > (implicitly) converting that to a 'B' when calling the actual function), or > you may write a custom from_python converter. > > Regards, > ? ? ? ?Stefan > > -- > > ? ? ?...ich hab' noch einen Koffer in Berlin... > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From nat at lindenlab.com Fri Oct 2 17:48:08 2009 From: nat at lindenlab.com (Nat Goodspeed) Date: Fri, 02 Oct 2009 11:48:08 -0400 Subject: [C++-sig] Conversion from Python to C++ In-Reply-To: References: <4AC60CAC.4050907@sympatico.ca> Message-ID: <4AC620B8.6030904@lindenlab.com> Michele De Stefano wrote: > I'd like to write a custom from_python converter, but the point is > that I've not understood how it works. Did you see Austin Bingham's recent post on another thread? > If it's any help, I wrote a small bit on the details of writing > converters. It might help clarify some of the mechanics which, I > agree, are a bit mysterious: > > http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ From micdestefano at gmail.com Fri Oct 2 18:02:22 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Fri, 2 Oct 2009 18:02:22 +0200 Subject: [C++-sig] Conversion from Python to C++ In-Reply-To: <4AC620B8.6030904@lindenlab.com> References: <4AC60CAC.4050907@sympatico.ca> <4AC620B8.6030904@lindenlab.com> Message-ID: Honestly, no. Thank you for pointing me to that. I will look at it and if I have problems again, I will post again. Thank you very much. 2009/10/2 Nat Goodspeed : > Michele De Stefano wrote: > >> I'd like to write a custom from_python converter, but the point is >> that I've not understood how it works. > > Did you see Austin Bingham's recent post on another thread? > >> If it's any help, I wrote a small bit on the details of writing >> converters. It might help clarify some of the mechanics which, I >> agree, are a bit mysterious: >> >> >> ?http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/ > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From rfritz333 at gmail.com Mon Oct 5 02:36:34 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Mon, 5 Oct 2009 00:36:34 +0000 (UTC) Subject: [C++-sig] Setting up a boost.python workflow on a Mac Message-ID: I have just successfully--I hope--done this & I want to get my notes down before I forget the problems I encountered. These occurred with Boost 1.39 and Mac OS 10.5.8. 1. Bjam did not automatically detect the Mac OS environment and compilation consistently failed. So, I added the following line to /etc/site-config.jam: using darwin ; 2. I built boost.python according to the getting started guide. This left me with four files in stage/bin: libboost_python-xgcc40-mt-1_39.a libboost_python-xgcc40-mt-1_39.dylib libboost_python-xgcc40-mt.a libboost_python-xgcc40-mt.dylib 3. The install command recommended by bjam was "bjam install --prefix=". I attempted to use the command, and found it consistently tried to place files in /lib. A manual move to my target library directory fixed that problem. 4. It turned out that the default build script automatically looked for debug libraries, which weren't automatically built. I tried "bjam debug" and it placed the following four files in stage/bin: libboost_python-xgcc40-mt-d-1_39.a libboost_python-xgcc40-mt-d-1_39.dylib libboost_python-xgcc40-mt-d.a libboost_python-xgcc40-mt-d.dylib These I also placed manually. 5. I then discovered that the sample Jamroot provided did not support multi-threaded (*-mt-*) libraries. I added the following symbolic links to my target directory: libboost_python-xgcc40-1.39.dylib -> libboost_python-xgcc40-mt-1_39.dylib libboost_python-xgcc40-d-1_39.dylib -> libboost_python-xgcc40-mt-d-1_39.dylib 6. Voila! My test application built and apparently ran. -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From blake at hailmail.net Mon Oct 5 03:11:36 2009 From: blake at hailmail.net (Dane Springmeyer) Date: Sun, 4 Oct 2009 18:11:36 -0700 Subject: [C++-sig] Setting up a boost.python workflow on a Mac In-Reply-To: References: Message-ID: Hello Randolph, On Oct 4, 2009, at 5:36 PM, Randolph Fritz wrote: > I have just successfully--I hope--done this & I want to get my notes > down before I forget the problems I encountered. These occurred > with Boost 1.39 and Mac OS 10.5.8. > > 1. Bjam did not automatically detect the Mac OS environment and > compilation consistently failed. So, I added the following line to > /etc/site-config.jam: > using darwin ; > You can pass as a command line option to bjam: ./bjam toolset=darwin (see also: https://trac.mapnik.org/wiki/MacInstallation#Step1:RouteBC) Dane -------------- next part -------------- An HTML attachment was scrubbed... URL: From gustavoborges at rjxcapital.com Thu Oct 8 21:44:26 2009 From: gustavoborges at rjxcapital.com (Gustavo Adolfo Borges) Date: Thu, 8 Oct 2009 16:44:26 -0300 Subject: [C++-sig] call_method crash Message-ID: <948705c00910081244i469e8d3ehfccc951036a7b75a@mail.gmail.com> Since Python Win32 lib does not implement DDE Advise Loop and i need it for a project, i guessed that Boost Python would be a way to integrate the ddeml lib with my python code. I guessed i could just call call_method inside the DDE Callback function, but when i do that python crashes. I can't(or couldnt find how to) add the DDE Callback function to the Python Module and i tried through a 2 stages call(DdeCallback calls a Python Module function that call_method) without success. Everything else works great... I can connect to the DDE Server, the advise loop works, my setPyCallback/getPyCallback works... I just can't get any python to work on the C++ DDECallback function. Here is part of the code ------------------ PyObject* myPythonCallback; void CallPy(TCHAR SomeValue){ boost::python::call(myPythonCallback,SomeValue); } HDDEDATA CALLBACK DdeCallback(UINT wType,UINT uFmt,HCONV hconv,HSZ hsz1,HSZ hsz2,HDDEDATA hData,DWORD dwData1,DWORD dwData2){ .......... switch (wType) { case XTYP_ADVDATA: .................. bunch of code .......... CallPy(mybuffer); return((HDDEDATA)DDE_FACK); } int ddeConnect(); void ddeAdvise(TCHAR* topic); void setCallback(PyObject* p){ boost::python::call(p,"3");// test calling function and WORKS myPythonCallback = p; } BOOST_PYTHON_MODULE(extending) { using namespace boost::python; def("ddeConnect", ddeConnect); def("ddeAdvise", ddeAdvise); def("ddeSetCallback", setCallback); def("CallPy", CallPy); } ------------- Python ------------ import extending import wx import justAFrame def mCB (valor): print "mCB",str(valor) return float(str(valor)) class MyFrame(justAFrame.MyFrame): def initAfter (self): justAFrame.MyFrame.initAfter(self) extending.ddeConnect() extending.ddeSetCallback(mCB) extending.CallPy("1") #WORKS extending.ddeAdvise("0012PETR4;1") app = wx.PySimpleApp() frame=MyFrame(None,title="DDE Test") app.MainLoop() -------------- How can i make this DdeCallback to interact with a python function defined by the user ? Is there a better way to do this ? I'm open to suggestions. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rogeeff at gmail.com Fri Oct 9 08:25:26 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Fri, 9 Oct 2009 06:25:26 +0000 (UTC) Subject: [C++-sig] "pass all args in list" syntax Message-ID: Hi, In native Python I can do something like this: def goo(a,b,c): return a+b+c ll = [1,2,3] goo( *ll ) And it will pass all the arguments properly. I need similar functionality in C++: Given bp::object func; bp::list args; I'd like to invoke the function like this func( *args ); Is there syntax in Boost.Python to achieve this? Or I need to resort to ugly switch statement? Gennadiy From seefeld at sympatico.ca Fri Oct 9 13:58:40 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 09 Oct 2009 07:58:40 -0400 Subject: [C++-sig] "pass all args in list" syntax In-Reply-To: References: Message-ID: <4ACF2570.8030205@sympatico.ca> On 10/09/2009 02:25 AM, Gennadiy Rozental wrote: > Hi, > > In native Python I can do something like this: > > def goo(a,b,c): > return a+b+c > > ll = [1,2,3] > goo( *ll ) > > And it will pass all the arguments properly. I need similar functionality in C++: > > Given > > bp::object func; > bp::list args; > > I'd like to invoke the function like this func( *args ); > > Is there syntax in Boost.Python to achieve this? Or I need to resort to ugly > switch statement? > I added support for the above quite a while ago (and I'm assured that this time it even made it into the release branch in time ;-) ). Thus, you can construct a list and keyword, then pass to a python callable as '*args' and '**kwds' respectively. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From rogeeff at gmail.com Fri Oct 9 22:19:59 2009 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Fri, 9 Oct 2009 20:19:59 +0000 (UTC) Subject: [C++-sig] "pass all args in list" syntax References: <4ACF2570.8030205@sympatico.ca> Message-ID: Stefan Seefeld sympatico.ca> writes: > I added support for the above quite a while ago (and I'm assured that > this time it even made it into the release branch in time ). > Thus, you can construct a list and keyword, then pass to a python > callable as '*args' and '**kwds' respectively. Right. So no luck with 1.33.1 guess ;) Will it get into 1.41? Gennadiy From seefeld at sympatico.ca Fri Oct 9 23:09:31 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Fri, 09 Oct 2009 17:09:31 -0400 Subject: [C++-sig] "pass all args in list" syntax In-Reply-To: References: <4ACF2570.8030205@sympatico.ca> Message-ID: <4ACFA68B.4070004@sympatico.ca> On 10/09/2009 04:19 PM, Gennadiy Rozental wrote: > Stefan Seefeld sympatico.ca> writes: > >> I added support for the above quite a while ago (and I'm assured that >> this time it even made it into the release branch in time ). >> Thus, you can construct a list and keyword, then pass to a python >> callable as '*args' and '**kwds' respectively. >> > Right. > > So no luck with 1.33.1 guess ;) > > Will it get into 1.41? > With 'this time' I was referring to the 1.40 release. So yes, it will be in 1.41, too. :-) Stefan -- ...ich hab' noch einen Koffer in Berlin... From yooi at msn.com Sat Oct 10 06:00:52 2009 From: yooi at msn.com (Cheng Lee) Date: Sat, 10 Oct 2009 04:00:52 +0000 Subject: [C++-sig] [Urgent Question] Import Qt builded Lib into python with Boost.python Message-ID: Hello All, Our project made some of the functions with Qt and also encapsulate them with dll library, the imported module, we made it following the boost.python syntax, was built successfully, and imported into python 2.6.2 with no errors, but our issues are, the functions donot work, no response as our investigation, it supposes to be Qt signal/slot donot work in the python module I made a simple example below: Would someone help me check what codes i need add to make the signal/slot work in the python, Thanks a lot Boost 1.40 Python 2.6.2 ++++++++++++++++++++++++++++++++++++++++++++++++++.h #ifndef SIGALE_H #define SIGALE_H #include class SignalMine : public QObject { Q_OBJECT public: SignalMine(QObject* parent = 0); void submit(void){emit trigger();} signals: void trigger(void); protected slots: void printOut(void); }; #endif ++++++++++++++++++++++++++++++++++++++++++++++++++.cpp #include #include"example.h" SignalMine::SignalMine(QObject* parent):QObject(parent) { connect(this, SIGNAL(trigger()), this, SLOT(printOut())); } void SignalMine::printOut() { cout << "Get signal!" << endl; } //! for boost.python #include using namespace boost::python; BOOST_PYTHON_MODULE(SIGN) { class_("QObject"); class_>("SignalMineller") .def("submit", &SignalMine::submit); } _________________________________________________________________ Keep your friends updated?even when you?re not signed in. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_5:092010 -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists_ravi at lavabit.com Sat Oct 10 17:58:46 2009 From: lists_ravi at lavabit.com (Ravi) Date: Sat, 10 Oct 2009 11:58:46 -0400 Subject: [C++-sig] [python] Function objects in place of member functions Message-ID: <200910101158.46996.lists_ravi@lavabit.com> Hello, If a free function 'func' has X* as its first argument, then, boost.python allows it to be bound to a member function on the python side, i.e., the following is legal: void func( X* x, arg1_t arg ) { ... } class_( "X" ).def( "func", &func ); In order to use a function object in place of a free function, one must specialize/overload boost::python::detail::get_signature which, for some reason, does not account for function objects. Here's a very simple example that works: ---------------------------------------------- #include struct X { int y; }; // Function object struct Z { int operator()( X *x, int z ) { return z + x->y; } }; namespace boost { namespace python { namespace detail { mpl::vector get_signature( Z&, X* ) {return mpl::vector();} }}} #include #include BOOST_PYTHON_MODULE( mft ) { boost::python::class_( "X" ) .def( "z", Z() ).def_readwrite( "y", &X::y ); } ------------------------------------------------- However, note that the overload of get_signature precedes the inclusion of the boost.python headers, which is extremely inconvenient. However, if the headers are moved to their proper location as in the following, ---------------------------------------------- #include #include #include struct X { int y; }; // Function object struct Z { int operator()( X *x, int z ) { return z + x->y; } }; namespace boost { namespace python { namespace detail { boost::mpl::vector get_signature( Z&, X* ) {return boost::mpl::vector();} }}} BOOST_PYTHON_MODULE( mft ) { boost::python::class_( "X" ) .def( "z", Z() ).def_readwrite( "y", &X::y ); } ------------------------------------------------- the compilation fails with the following error message (gcc 4.4.1 with boost 1.37 or 1.39): $ g++ -Wall -shared -o mft.so memft.cc -lboost_python-mt - I/usr/include/python2.6 -fPIC In file included from memft.cc:1: /usr/include/boost/python/class.hpp: In member function ?void boost::python::class_::def_impl(T*, const char*, Fn, const Helper&, ...) [with T = X, Fn = Z, Helper = boost::python::detail::def_helper, W = X, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]?: /usr/include/boost/python/class.hpp:235: instantiated from ?boost::python::class_& boost::python::class_::def(const char*, F) [with F = Z, W = X, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]? memft.cc:16: instantiated from here /usr/include/boost/python/class.hpp:536: error: no matching function for call to ?get_signature(Z&, X*)? Why is the overloaded get_signature not picked up when it is declared *after* the inclusion of the headers? The reason for using function objects is to change the argument types of a member function of X as seen by python; for example, the functor would have an argument type 'double' and would then internally convert the received 'double' argument from the python side into some custom type prior to passing it to the member function of X. In other words, the functor would act as a C++ equivalent of a python decorator. Regards, Ravi From troy at resophonic.com Mon Oct 12 01:44:29 2009 From: troy at resophonic.com (troy d. straszheim) Date: Sun, 11 Oct 2009 19:44:29 -0400 Subject: [C++-sig] [python] Function objects in place of member functions In-Reply-To: <200910101158.46996.lists_ravi@lavabit.com> References: <200910101158.46996.lists_ravi@lavabit.com> Message-ID: <4AD26DDD.5020402@resophonic.com> Ravi wrote: [snip] > > In order to use a function object in place of a free function, one must > specialize/overload > boost::python::detail::get_signature > which, for some reason, does not account for function objects. Here's a very > simple example that works: > [snip] > > However, note that the overload of get_signature precedes the inclusion of the > boost.python headers, which is extremely inconvenient. However, if the headers > are moved to their proper location as in the following, > [snip] > > Why is the overloaded get_signature not picked up when it is declared *after* > the inclusion of the headers? > I'm not sure why it isn't picked up. I've been working in this area, replacing most of detail/caller.hpp and detail/invoke.hpp with boost.fusion, seen here: http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python/detail/caller.hpp In the process, I overhauled get_signature to use boost::function_types, and to be a metafunction, not a function: http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python/signature.hpp The overall effect is a lot less preprocessor stuff to look around. I have function objects (given a specialization of get_signature), and boost::function (only up to 3 arguments ATM) working, here's the test (which passes): ///////////////////////////////////// #include #include #include #include namespace mpl = boost::mpl; struct X { int y; }; struct FnObject { typedef int result_type; int operator()(X *x, int z) const { return z + x->y; } }; int f1(X* x) { return x->y ; } int f2(X* x, int i) { return x->y * i; } int f3(X* x, int i, int j) { return x->y * i + j; } namespace boost { namespace python { namespace detail { template<> struct get_signature { typedef mpl::vector type; }; } } } using namespace boost::python; BOOST_PYTHON_MODULE( function_objects_ext ) { FnObject fobj; boost::function bf0(fobj); boost::function bf1(f1); boost::function bf2(f2); boost::function bf3(f3); boost::python::class_( "X" ) .def( "fobj", fobj) .def( "bf0", bf0) .def( "bf1", bf1) .def( "bf2", bf2) .def( "bf3", bf3) .def_readwrite( "y", &X::y ) ; } ///////////////////////////// >>> from function_objects_ext import * >>> x = X() >>> x.y = 13 >>> x.fobj(12) 25 >>> x.bf1() 13 >>> x.bf2(2) 26 >>> x.bf3(2, -27) -1 ///////////////////////////// I'm fairly new to the internals of boost.python, and only just now got this working... Do you see problems with this, specifically the conversion of get_signature from function to metafunction? -t From lists_ravi at lavabit.com Mon Oct 12 02:32:59 2009 From: lists_ravi at lavabit.com (Ravi) Date: Sun, 11 Oct 2009 20:32:59 -0400 Subject: [C++-sig] [python] Function objects in place of member functions In-Reply-To: <4AD26DDD.5020402@resophonic.com> References: <200910101158.46996.lists_ravi@lavabit.com> <4AD26DDD.5020402@resophonic.com> Message-ID: <200910112032.59896.lists_ravi@lavabit.com> On Sunday 11 October 2009 19:44:29 troy d. straszheim wrote: > > Why is the overloaded get_signature not picked up when it is declared > > after the inclusion of the headers? > > I'm not sure why it isn't picked up. Does that mean that you can reproduce the problem I pointed out? > I've been working in this area, > replacing most of detail/caller.hpp and detail/invoke.hpp with > boost.fusion, seen here: > > http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python > /detail/caller.hpp > > In the process, I overhauled get_signature to use boost::function_types, > and to be a metafunction, not a function: > > http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python > /signature.hpp IMHO, this is the right way to do it. This avoids relying on the compiler to optimize out all the ugly tag-dispatching. Of course, Dave A & Ralf WGK did not have function types when they wrote this originally. [snip] > boost::function bf0(fobj); Why do you need to use boost::function here? Shouldn't the type be deduced automatically? > I'm fairly new to the internals of boost.python, and only just now got > this working... Do you see problems with this, specifically the > conversion of get_signature from function to metafunction? I don't see any problems with the conversion of get_signature to a metafunction. Do compile times get any longer? Regards, Ravi From rfritz333 at gmail.com Mon Oct 12 06:14:46 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Mon, 12 Oct 2009 04:14:46 +0000 (UTC) Subject: [C++-sig] Boost.python: extracting an array Message-ID: Is there any way to extract a vector of floats from a python array? In Python, can I write something like: from array import array from bpclass import foo vec = array('f', (1,2,3)) foo ([vec]) And, in C++: void bpclass::foo (list v) { ... extract< {magic} >(v[0]) ... Or would it be better to replace the array with a list? -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From hwang.roman at gmail.com Mon Oct 12 08:59:58 2009 From: hwang.roman at gmail.com (Roman Hwang) Date: Mon, 12 Oct 2009 15:59:58 +0900 Subject: [C++-sig] Returning pointer to abstract class from pure virtual class method Message-ID: <499f6e2b0910112359m1c2f9fe7j7fd8fb65066af95c@mail.gmail.com> Hello. I'm new to Python, but really want to use it with my C++ code. I faced a problem while returning pointer to abstract class from pure virtual class method. I tried to search the web, but found nothing. struct ICoreWrapper : ICore, wrapper { virtual IRegistry* CreateRegistry() { return this->get_override("CreateRegistry")(); } }; struct IRegistryWrapper : IRegistry, wrapper { virtual void DoSomestuff() { return this->get_override("DoSomestuff")(); } }; ICore* CreateCoreW() { return new CCore; } BOOST_PYTHON_MODULE_INIT(CorePy) { class_("IRegistry") .def("DoSomestuff", pure_virtual(&IRegistry::DoSomestuff)) ; class_("ICore") .def("CreateRegistry", pure_virtual(&ICore::CreateRegistry), return_value_policy()) ; def("CreateCore", CreateCoreW, return_value_policy()); } The Python code looks like this: >>> import CorePy >>> c = CorePy.CreateCore() >>> b = c.CreateRegistry() I get Debug Error Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. Please tell me what I do wrong. Or whether this code is supported or not. Thanks Roman Hwang. From diepen at astron.nl Mon Oct 12 09:38:42 2009 From: diepen at astron.nl (Ger van Diepen) Date: Mon, 12 Oct 2009 09:38:42 +0200 Subject: [C++-sig] Compile error when using exception_translation.hpp Message-ID: <4AD2F921.6086.00A9.0@astron.nl> When compiling the following code using gcc-4.3.2 and boost-1.37, I get errors as listed at the end. It also fails for boost-1.40 and gcc-4.3.4. It is solved when patching translate_exception.hpp by adding # include Is it a Boost-Python problem or do I do something wrong? Of course, I can include that file in my own code, but that does not seem the correct solution to me. Thanks, Ger van Diepen #include #include void translate_stdexcp (const std::exception& e) { PyErr_SetString(PyExc_RuntimeError, e.what()); } //# Note that the most general exception must be registered first. void register_convert_excp() { boost::python::register_exception_translator (&translate_stdexcp); } /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:34: error: expected nested-name-specifier before ?add_reference? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:34: error: expected ?;? before ?::operator()(const boost::python::detail::exception_handler&, const boost::function0&, typename boost::call_traits::param_type) const?: /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected type-specifier before ?exception_cref? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `)' before ?e? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `{' before ?e? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: ?e? was not declared in this scope /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `;' before ?)? token From troy at resophonic.com Mon Oct 12 14:47:22 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 12 Oct 2009 08:47:22 -0400 Subject: [C++-sig] [python] Function objects in place of member functions In-Reply-To: <200910112032.59896.lists_ravi@lavabit.com> References: <200910101158.46996.lists_ravi@lavabit.com> <4AD26DDD.5020402@resophonic.com> <200910112032.59896.lists_ravi@lavabit.com> Message-ID: <4AD3255A.9090505@resophonic.com> Ravi wrote: > On Sunday 11 October 2009 19:44:29 troy d. straszheim wrote: >>> Why is the overloaded get_signature not picked up when it is declared >>> after the inclusion of the headers? >> I'm not sure why it isn't picked up. > > Does that mean that you can reproduce the problem I pointed out? > Yes I can. >> I've been working in this area, >> replacing most of detail/caller.hpp and detail/invoke.hpp with >> boost.fusion, seen here: >> >> http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python >> /detail/caller.hpp >> >> In the process, I overhauled get_signature to use boost::function_types, >> and to be a metafunction, not a function: >> >> http://gitorious.org/~straszheim/boost/straszheim/blobs/python/boost/python >> /signature.hpp > > IMHO, this is the right way to do it. This avoids relying on the compiler to > optimize out all the ugly tag-dispatching. Of course, Dave A & Ralf WGK did > not have function types when they wrote this originally. > Yes, the code was all dated ~2002. There are more corners of the code that could use modernization as well. > [snip] > >> boost::function bf0(fobj); > > Why do you need to use boost::function here? Shouldn't the type be deduced > automatically? > Note that the .def() of the various boost::function objects work without requiring the user to specialize get_signature, (since this modified get_signature metafunction knows about boost::function objects). Here's a different (working) example: #include #include #include #include #include struct X { int y; }; struct add_to { template T operator()(X* x, T t) const { return t + x->y; } std::string operator()(X* x, std::string s) { return s + boost::lexical_cast(x->y); } }; using namespace boost::python; BOOST_PYTHON_MODULE( function_objects_ext ) { add_to add_to_inst; boost::function f_int(add_to_inst); boost::function f_string(add_to_inst); boost::python::class_( "X" ) .def_readwrite( "y", &X::y ) .def( "add_to", f_int) .def( "add_to", f_string) ; } >>> from function_objects_ext import * >>> x = X() >>> x.y = 13 >>> x.add_to(1) 14 >>> x.add_to("foo") 'foo13' Some musings: I think interoperability with boost::function is a Good Thing, but in the example above (and the previous), all it does is give def() a way to tell what the signature of the function object is at compile time, and it does so at a runtime cost. A specialization of get_signature works, but strikes me as kinda ugly (it should at least be moved out of 'detail' if it is a user customization point). How about something like class_("T") .def("f1", f1, sig) .def("fi", f1) Which looks pretty straightforward when dealing with function objects, but when dealing with overloads, things get tricky: void f2(T*, int); void f2(T*, double); class_("T") .def("f2", f2) // #1 error .def("f2", (void(*)(T*, int))f2) // #2 ok but ugly .def("f2", f2) // #3 works but tricky ; #1 is an error, because f2's type is undetermined. #2 is how you can fix #1 in current practice (or with an alias). #3 could work (I've tried, it works) if def, when passed a function type, only accepts pointers to functions of that type, so that the overload is resolved. But how to use this same form to also specify the types of arbitrary function objects... haven't thought about that yet. >> I'm fairly new to the internals of boost.python, and only just now got >> this working... Do you see problems with this, specifically the >> conversion of get_signature from function to metafunction? > > I don't see any problems with the conversion of get_signature to a > metafunction. Do compile times get any longer? I haven't checked this yet. I have other concerns re typechecking and automatic conversions... I'll go back and look more closely. -t From p.schellart at gmail.com Mon Oct 12 17:36:20 2009 From: p.schellart at gmail.com (Pim Schellart) Date: Mon, 12 Oct 2009 17:36:20 +0200 Subject: [C++-sig] Numpy ndarray as argument or return value using boost python Message-ID: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> Hi Everyone, I also posted this to the boost users list. I tried to find a good example for this but after spending two days on google and one day getting pyublas to compile I decided to call for help. I want to give a numpy ndarray as an argument to a c++ method, calculate something and return the output as an ndarray to Python. I would prefer not to use another library (such as PyUblas) for this so I do not have to add another dependency to my program. Since the latest information on boost python is quite outdated (uses numeric) I would like to know the following. 1. Is boost python still maintained or should I switch to another tool. 2. Is numpy supported, and if so, 3. can someone give me a basic example of how to use it. Kind regards, Pim Schellart From seefeld at sympatico.ca Mon Oct 12 19:57:21 2009 From: seefeld at sympatico.ca (Stefan Seefeld) Date: Mon, 12 Oct 2009 13:57:21 -0400 Subject: [C++-sig] Numpy ndarray as argument or return value using boost python In-Reply-To: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> References: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> Message-ID: <4AD36E01.4080303@sympatico.ca> On 10/12/2009 11:36 AM, Pim Schellart wrote: > Hi Everyone, > > I also posted this to the boost users list. > I tried to find a good example for this but after spending two days on > google and one day getting pyublas to compile I decided to call for > help. > I want to give a numpy ndarray as an argument to a c++ method, > calculate something and return the output as an ndarray to Python. > I would prefer not to use another library (such as PyUblas) for this > so I do not have to add another dependency to my program. > Since the latest information on boost python is quite outdated (uses > numeric) I would like to know the following. > > 1. Is boost python still maintained or should I switch to another tool. > Boost.Python is definitely maintained. > 2. Is numpy supported, and if so, > That is a good question, to which I don't have an answer. In fact, I submitted an issue about the docs (https://svn.boost.org/trac/boost/ticket/3340), as a first step to getting an up-to-date picture. Meanwhile, I have written my own wrapper for PyArray, as the existing one is by far not enough for my needs. (In particular, I need direct memory access.) I would be happy to share this code and move it into boost.python, if in fact everyone agrees that what exists should be replaced. David, Ralf, do you have an opinion on this ? > 3. can someone give me a basic example of how to use it. > Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... From AFoglia at princeton.com Mon Oct 12 19:54:43 2009 From: AFoglia at princeton.com (Anthony Foglia) Date: Mon, 12 Oct 2009 13:54:43 -0400 Subject: [C++-sig] Numpy ndarray as argument or return value using boost python In-Reply-To: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> References: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> Message-ID: <4AD36D63.1050207@princeton.com> Pim Schellart wrote: > I also posted this to the boost users list. Most of the Boost Python discussion goes on here, so this is probably the better group. > I want to give a numpy ndarray as an argument to a c++ method, > calculate something and return the output as an ndarray to Python. > I would prefer not to use another library (such as PyUblas) for this > so I do not have to add another dependency to my program. I did this myself last year, and here's what I can tell you. > 1. Is boost python still maintained or should I switch to another tool. Yes it is maintained. > 2. Is numpy supported, and if so, Yes and no. Boost.Python has a header for dealing with Numeric arrays that works just as well with NumPy. . But it works by passing all methods through the Python interpreter, so you will see no increase in speed compared to using a more low-level NumPy API. There is num_util header created by a third-party that claims to do a lot of the wrapping. I ended up not using it, but instead going getting using NumPy's C API directly and keeping the pointers wrapped in boost::python::handle objects as much as possible. > 3. can someone give me a basic example of how to use it. The num_util page has an example of their code. -- Anthony Foglia Princeton Consultants (609) 987-8787 x233 From cmbruns at stanford.edu Mon Oct 12 22:51:32 2009 From: cmbruns at stanford.edu (Christopher Bruns) Date: Mon, 12 Oct 2009 13:51:32 -0700 Subject: [C++-sig] [Py++] How to wrap default arg as enum with complicated scope? Message-ID: Below is a simplified example of a tricky wrapping problem I have encountered. The example remains somewhat complicated, but further simplification results in a file that causes no trouble. I get a compile error when I try to build the boost python code generated by the following case: #### test_enum.h #### struct System { struct ProjectOptions { enum Option { All = 1 }; ProjectOptions(Option); }; void project(ProjectOptions = ProjectOptions::All); }; #### end test_enum.h #### The trouble comes from the default value ('ProjectOptions::All') for the project() method. Notice also the constructor for ProjectOptions from Options. That is required for reproducing the trouble here. The resulting boost.python code is as follows: #### wrap_enum2.py #### from pyplusplus import module_builder mb = module_builder.module_builder_t(["test_enum2.h"] , gccxml_path = "gccxml.exe") mb.build_code_creator( module_name='test' ) mb.write_module( 'test_wrap_enum2.cpp' ) #### end wrap_enum2.py #### #### test_wrap_enum2.cpp #### // This file has been generated by Py++. #include "boost/python.hpp" #include "test_enum2.h" namespace bp = boost::python; BOOST_PYTHON_MODULE(test){ { //::System typedef bp::class_< System > System_exposer_t; System_exposer_t System_exposer = System_exposer_t( "System" ); bp::scope System_scope( System_exposer ); { //::System::ProjectOptions typedef bp::class_< System::ProjectOptions > ProjectOptions_exposer_t; ProjectOptions_exposer_t ProjectOptions_exposer = ProjectOptions_exposer_t( "ProjectOptions", bp::init< System::ProjectOptions::Option >(( bp::arg("arg0") )) ); bp::scope ProjectOptions_scope( ProjectOptions_exposer ); bp::enum_< System::ProjectOptions::Option>("Option") .value("All", System::ProjectOptions::All) .export_values() ; bp::implicitly_convertible< System::ProjectOptions::Option, System::ProjectOptions >(); } { //::System::project typedef void ( ::System::*project_function_type )( ::System::ProjectOptions ) ; System_exposer.def( "project" , project_function_type( &::System::project ) , ( bp::arg("arg0")=All ) ); } } } #### test_wrap_enum2.cpp #### The symbol "All" in the line ", ( bp::arg("arg0")=All ) );" is out of scope here. If I change the line from , ( bp::arg("arg0")=All ) ); // compile failure to , ( bp::arg("arg0")=System::ProjectOptions::All ) ); // works it compiles fine. Is there any way to instruct pyplusplus to generate the default argument value for the project() method with the scope "System::ProjectOptions::All"? Any enlightenment is much appreciated. --Chris Bruns From roman.yakovenko at gmail.com Tue Oct 13 00:39:04 2009 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Tue, 13 Oct 2009 00:39:04 +0200 Subject: [C++-sig] [Py++] How to wrap default arg as enum with complicated scope? In-Reply-To: References: Message-ID: <7465b6170910121539i4b16cc8am5ab1d38b42fc474@mail.gmail.com> On Mon, Oct 12, 2009 at 10:51 PM, Christopher Bruns wrote: > Below is a simplified example of a tricky wrapping problem I have > encountered. ?The example remains somewhat complicated, but further > simplification results in a file that causes no trouble. > I get a compile error when I try to build the boost python code > generated by the following case: > > #### test_enum.h #### > struct System { > ? ?struct ProjectOptions { > ? ? ? ?enum Option { > ? ? ? ? ? ?All = 1 > ? ? ? ?}; > ? ? ? ?ProjectOptions(Option); > ? ?}; > ? ?void project(ProjectOptions = ProjectOptions::All); > }; > #### end test_enum.h #### > > The trouble comes from the default value ('ProjectOptions::All') for > the project() method. ?Notice also the constructor for ProjectOptions > from Options. ?That is required for reproducing the trouble here. > > The resulting boost.python code is as follows: > ... > #### test_wrap_enum2.cpp #### > > The symbol "All" in the line ", ( bp::arg("arg0")=All ) );" is out of > scope here. ?If I change the line from > > ?, ( bp::arg("arg0")=All ) ); // compile failure > > to > > ?, ( bp::arg("arg0")=System::ProjectOptions::All ) ); // works > > it compiles fine. > > Is there any way to instruct pyplusplus to generate the default > argument value for the project() method with the scope > "System::ProjectOptions::All"? Yes: mb = module_builder_t(...) project = mb.mem_fun( 'project' ) project.arguments[0].default_value = "System::ProjectOptions::All" > Any enlightenment is much appreciated. Basically this is GCCXML limitations. The default argument could be full-blown C++ expression. GCCXML doesn't handles\dumps them. It do writes something for default arguments and Py++(pygccxml) try to decode what it is. May be the following link could help you: http://language-binding.net/pygccxml/upgrade_issues.html http://language-binding.net/pyplusplus/documentation/functions/functions.html Also try google, this problem was discussed on this, pygccxml and gccxml mailing lists. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From lists_ravi at lavabit.com Tue Oct 13 03:04:46 2009 From: lists_ravi at lavabit.com (Ravi) Date: Mon, 12 Oct 2009 21:04:46 -0400 Subject: [C++-sig] [python] Function objects in place of member functions In-Reply-To: <4AD3255A.9090505@resophonic.com> References: <200910101158.46996.lists_ravi@lavabit.com> <200910112032.59896.lists_ravi@lavabit.com> <4AD3255A.9090505@resophonic.com> Message-ID: <200910122104.46505.lists_ravi@lavabit.com> On Monday 12 October 2009 08:47:22 troy d. straszheim wrote: > >> boost::function bf0(fobj); > > > > > > Why do you need to use boost::function here? Shouldn't the type be > > deduced automatically? > > > > Note that the .def() of the various boost::function objects work without > requiring the user to specialize get_signature, (since this modified > get_signature metafunction knows about boost::function objects). [snip] > I think interoperability with boost::function is a Good Thing, but in > the example above (and the previous), all it does is give def() a way to > tell what the signature of the function object is at compile time, and > it does so at a runtime cost. At least for my case, that extra virtual function call is a killer. > A specialization of get_signature works, > but strikes me as kinda ugly (it should at least be moved out of > 'detail' if it is a user customization point). How about something like > > class_("T") > .def("f1", f1, sig) > .def("fi", f1) I'd rather have something along the lines of .def< mpl::vector >("f1",f1) by using function_types to compose the currect function signature. Alternatively, one could have the sig<> template above be a def_visitor and take the appropriate template arguments without the need to modify class_::def at all. > >> I'm fairly new to the internals of boost.python, and only just now got > >> this working... Do you see problems with this, specifically the > >> conversion of get_signature from function to metafunction? > > > > > > I don't see any problems with the conversion of get_signature to a > > metafunction. Do compile times get any longer? > > I haven't checked this yet. I have other concerns re typechecking and > automatic conversions... Care to elaborate? Regards, Ravi From lists_ravi at lavabit.com Tue Oct 13 03:11:44 2009 From: lists_ravi at lavabit.com (Ravi) Date: Mon, 12 Oct 2009 21:11:44 -0400 Subject: [C++-sig] Numpy ndarray as argument or return value using boost python In-Reply-To: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> References: <7d3dada90910120836q6ba2b545sede71b6aef0543fe@mail.gmail.com> Message-ID: <200910122111.44171.lists_ravi@lavabit.com> On Monday 12 October 2009 11:36:20 Pim Schellart wrote: > 1. Is boost python still maintained or should I switch to another tool. > 2. Is numpy supported, and if so, > 3. can someone give me a basic example of how to use it. Please see http://mail.python.org/pipermail/cplusplus-sig/2008-October/013825.html which supports numpy arrays with and without copying, along with pass by reference and pass by value. Regards, Ravi From p.schellart at gmail.com Tue Oct 13 12:18:32 2009 From: p.schellart at gmail.com (Pim Schellart) Date: Tue, 13 Oct 2009 12:18:32 +0200 Subject: [C++-sig] Cplusplus-sig Digest, Vol 13, Issue 11 In-Reply-To: References: Message-ID: <7d3dada90910130318t79361207sa7110a416c0f841e@mail.gmail.com> Dear Ravi, thanks for the link. I'll be sure to try that. Any chance this will be included (and documented) in boost python? Numpy is needed for just about any scientific software package using Python and it would be a real plus if boost Python had an easy to use interface to C++ for it. Kind regards, Pim Schellart 2009/10/13 : > Send Cplusplus-sig mailing list submissions to > ? ? ? ?cplusplus-sig at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > ? ? ? ?http://mail.python.org/mailman/listinfo/cplusplus-sig > or, via email, send a message with subject or body 'help' to > ? ? ? ?cplusplus-sig-request at python.org > > You can reach the person managing the list at > ? ? ? ?cplusplus-sig-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Cplusplus-sig digest..." > > > Today's Topics: > > ? 1. Re: [Py++] How to wrap default arg as enum with ? complicated > ? ? ?scope? (Roman Yakovenko) > ? 2. Re: [python] Function objects in place of member functions (Ravi) > ? 3. Re: Numpy ndarray as argument or return value using boost > ? ? ?python (Ravi) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Tue, 13 Oct 2009 00:39:04 +0200 > From: Roman Yakovenko > To: "Development of Python/C++ integration" > Subject: Re: [C++-sig] [Py++] How to wrap default arg as enum with > ? ? ? ?complicated scope? > Message-ID: > ? ? ? ?<7465b6170910121539i4b16cc8am5ab1d38b42fc474 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > On Mon, Oct 12, 2009 at 10:51 PM, Christopher Bruns > wrote: >> Below is a simplified example of a tricky wrapping problem I have >> encountered. ?The example remains somewhat complicated, but further >> simplification results in a file that causes no trouble. >> I get a compile error when I try to build the boost python code >> generated by the following case: >> >> #### test_enum.h #### >> struct System { >> ? ?struct ProjectOptions { >> ? ? ? ?enum Option { >> ? ? ? ? ? ?All = 1 >> ? ? ? ?}; >> ? ? ? ?ProjectOptions(Option); >> ? ?}; >> ? ?void project(ProjectOptions = ProjectOptions::All); >> }; >> #### end test_enum.h #### >> >> The trouble comes from the default value ('ProjectOptions::All') for >> the project() method. ?Notice also the constructor for ProjectOptions >> from Options. ?That is required for reproducing the trouble here. >> >> The resulting boost.python code is as follows: >> ... >> #### test_wrap_enum2.cpp #### >> >> The symbol "All" in the line ", ( bp::arg("arg0")=All ) );" is out of >> scope here. ?If I change the line from >> >> ?, ( bp::arg("arg0")=All ) ); // compile failure >> >> to >> >> ?, ( bp::arg("arg0")=System::ProjectOptions::All ) ); // works >> >> it compiles fine. >> >> Is there any way to instruct pyplusplus to generate the default >> argument value for the project() method with the scope >> "System::ProjectOptions::All"? > > Yes: > > mb = module_builder_t(...) > project = mb.mem_fun( 'project' ) > project.arguments[0].default_value = "System::ProjectOptions::All" > >> Any enlightenment is much appreciated. > > Basically this is GCCXML limitations. The default argument could be > full-blown C++ expression. GCCXML doesn't handles\dumps them. It do > writes something for default arguments and Py++(pygccxml) try to > decode what it is. > > May be the following link could help you: > http://language-binding.net/pygccxml/upgrade_issues.html > http://language-binding.net/pyplusplus/documentation/functions/functions.html > > Also try google, this problem was discussed on this, pygccxml and > gccxml mailing lists. > > HTH > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > > > ------------------------------ > > Message: 2 > Date: Mon, 12 Oct 2009 21:04:46 -0400 > From: Ravi > To: "Development of Python/C++ integration" > Subject: Re: [C++-sig] [python] Function objects in place of member > ? ? ? ?functions > Message-ID: <200910122104.46505.lists_ravi at lavabit.com> > Content-Type: Text/Plain; ?charset="iso-8859-1" > > On Monday 12 October 2009 08:47:22 troy d. straszheim wrote: >> >> ? ?boost::function bf0(fobj); >> > >> > >> > Why do you need to use boost::function here? Shouldn't the type be >> > deduced ?automatically? >> > >> >> Note that the .def() of the various boost::function objects work without >> requiring the user to specialize get_signature, (since this modified >> get_signature metafunction knows about boost::function objects). > > [snip] > >> I think interoperability with boost::function is a Good Thing, but in >> the example above (and the previous), all it does is give def() a way to >> tell what the signature of the function object is at compile time, and >> it does so at a runtime cost. > > At least for my case, that extra virtual function call is a killer. > >> A specialization of get_signature works, >> but strikes me as kinda ugly (it should at least be moved out of >> 'detail' if it is a user customization point). ?How about something like >> >> ? ?class_("T") >> ? ? ?.def("f1", f1, sig) >> ? ? ?.def("fi", f1) > > I'd rather have something along the lines of > ? ? ?.def< mpl::vector >("f1",f1) > by using function_types to compose the currect function signature. > Alternatively, one could have the sig<> template above be a def_visitor and > take the appropriate template arguments without the need to modify class_::def > at all. > >> >> I'm fairly new to the internals of boost.python, and only just now got >> >> this working... ?Do you see problems with this, specifically the >> >> conversion of get_signature from function to metafunction? >> > >> > >> > I don't see any problems with the conversion of get_signature to a >> > metafunction. Do compile times get any longer? >> >> I haven't checked this yet. ?I have other concerns re typechecking and >> automatic conversions... > > Care to elaborate? > > Regards, > Ravi > > > > > ------------------------------ > > Message: 3 > Date: Mon, 12 Oct 2009 21:11:44 -0400 > From: Ravi > To: "Development of Python/C++ integration" > Subject: Re: [C++-sig] Numpy ndarray as argument or return value using > ? ? ? ?boost ? python > Message-ID: <200910122111.44171.lists_ravi at lavabit.com> > Content-Type: Text/Plain; ?charset="iso-8859-1" > > On Monday 12 October 2009 11:36:20 Pim Schellart wrote: >> 1. Is boost python still maintained or should I switch to another tool. >> 2. Is numpy supported, and if so, >> 3. can someone give me a basic example of how to use it. > > Please see > ?http://mail.python.org/pipermail/cplusplus-sig/2008-October/013825.html > which supports numpy arrays with and without copying, along with pass by > reference and pass by value. > > Regards, > Ravi > > > > ------------------------------ > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > > End of Cplusplus-sig Digest, Vol 13, Issue 11 > ********************************************* > From loeb at fkp.tu-darmstadt.de Tue Oct 13 15:44:42 2009 From: loeb at fkp.tu-darmstadt.de (=?ISO-8859-1?Q?Daniel_L=F6b?=) Date: Tue, 13 Oct 2009 15:44:42 +0200 Subject: [C++-sig] object constructor + integer == fail Message-ID: <4AD4844A.7070302@fkp.tu-darmstadt.de> Hi! I seem to be unable to call the constructor of "object" with an integer parameter. Working example: #include #include using namespace boost::python; using std::cout; using std::endl; int main() { object toast(3); cout << extract(toast) << endl; } It compiles just fine, but dies with a segmentation fault on execution of the first line within main. Backtrace: 0x00007ffff7ac9ca3 in PyInt_FromLong () from /usr/lib/libpython2.5.so.1.0 #1 0x0000000000401860 in arg_to_python (this=0x7fffffffeb30, x=@0x7fffffffebdc) at /usr/include/boost/python/converter/builtin_converters.hpp:113 #2 0x0000000000401888 in boost::python::api::object_initializer_impl::get (x=@0x7fffffffebdc) at /usr/include/boost/python/object_core.hpp:374 #3 0x00000000004018cb in boost::python::api::object_base_initializer (x=@0x7fffffffebdc) at /usr/include/boost/python/object_core.hpp:296 #4 0x00000000004018e7 in object (this=0x7fffffffebd0, x=@0x7fffffffebdc) at /usr/include/boost/python/object_core.hpp:315 #5 0x0000000000401196 in main () at bp_bug.cpp:10 Doing the same as above with a string instead of an integer works fine. I'm running debian with libboost-python1.38.0 . Greetings, Daniel From troy at resophonic.com Tue Oct 13 16:12:32 2009 From: troy at resophonic.com (troy d. straszheim) Date: Tue, 13 Oct 2009 10:12:32 -0400 Subject: [C++-sig] object constructor + integer == fail In-Reply-To: <4AD4844A.7070302@fkp.tu-darmstadt.de> References: <4AD4844A.7070302@fkp.tu-darmstadt.de> Message-ID: <4AD48AD0.5060104@resophonic.com> Daniel L?b wrote: > Hi! > > I seem to be unable to call the constructor of "object" with an integer > parameter. > Working example: > > #include > #include > > using namespace boost::python; > using std::cout; > using std::endl; > > int main() > { > object toast(3); > cout << extract(toast) << endl; > } > > It compiles just fine, but dies with a segmentation fault on execution > of the first line within main. > Does calling Py_Initialize() help? -t From loeb at fkp.tu-darmstadt.de Tue Oct 13 16:19:02 2009 From: loeb at fkp.tu-darmstadt.de (=?ISO-8859-1?Q?Daniel_L=F6b?=) Date: Tue, 13 Oct 2009 16:19:02 +0200 Subject: [C++-sig] object constructor + integer == fail In-Reply-To: <4AD48AD0.5060104@resophonic.com> References: <4AD4844A.7070302@fkp.tu-darmstadt.de> <4AD48AD0.5060104@resophonic.com> Message-ID: <4AD48C56.6010203@fkp.tu-darmstadt.de> troy d. straszheim wrote: > Daniel L?b wrote: >> Hi! >> >> I seem to be unable to call the constructor of "object" with an >> integer parameter. >> Working example: >> >> #include >> #include >> >> using namespace boost::python; >> using std::cout; >> using std::endl; >> >> int main() >> { >> object toast(3); >> cout << extract(toast) << endl; >> } >> >> It compiles just fine, but dies with a segmentation fault on execution >> of the first line within main. >> > > Does calling Py_Initialize() help? > Yes, that did it. Thank you! Best regards, Daniel From rwgk at yahoo.com Tue Oct 13 18:51:29 2009 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Tue, 13 Oct 2009 09:51:29 -0700 (PDT) Subject: [C++-sig] Compile error when using exception_translation.hpp In-Reply-To: <4AD2F921.6086.00A9.0@astron.nl> References: <4AD2F921.6086.00A9.0@astron.nl> Message-ID: <797789.92141.qm@web111402.mail.gq1.yahoo.com> translate_exception.hpp is in the "detail" directory. The convention is that this isn't a public interface. #include fixes your problem (at least under Fedora 8). Ralf ----- Original Message ---- From: Ger van Diepen To: boost-users at lists.boost.org; cplusplus-sig at python.org Sent: Mon, October 12, 2009 12:38:42 AM Subject: [C++-sig] Compile error when using exception_translation.hpp When compiling the following code using gcc-4.3.2 and boost-1.37, I get errors as listed at the end. It also fails for boost-1.40 and gcc-4.3.4. It is solved when patching translate_exception.hpp by adding # include Is it a Boost-Python problem or do I do something wrong? Of course, I can include that file in my own code, but that does not seem the correct solution to me. Thanks, Ger van Diepen #include #include void translate_stdexcp (const std::exception& e) { PyErr_SetString(PyExc_RuntimeError, e.what()); } //# Note that the most general exception must be registered first. void register_convert_excp() { boost::python::register_exception_translator (&translate_stdexcp); } /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:34: error: expected nested-name-specifier before ?add_reference? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:34: error: expected ?;? before ?::operator()(const boost::python::detail::exception_handler&, const boost::function0&, typename boost::call_traits::param_type) const?: /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected type-specifier before ?exception_cref? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `)' before ?e? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `{' before ?e? /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: ?e? was not declared in this scope /home/jds/Work/svn-usg/release/include/boost/python/detail/translate_exception.hpp:56: error: expected `;' before ?)? token _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From troy at resophonic.com Thu Oct 15 03:59:42 2009 From: troy at resophonic.com (troy d. straszheim) Date: Wed, 14 Oct 2009 21:59:42 -0400 Subject: [C++-sig] [python] python + phoenix In-Reply-To: <200910122104.46505.lists_ravi@lavabit.com> References: <200910101158.46996.lists_ravi@lavabit.com> <200910112032.59896.lists_ravi@lavabit.com> <4AD3255A.9090505@resophonic.com> <200910122104.46505.lists_ravi@lavabit.com> Message-ID: <4AD6820E.9040302@resophonic.com> Ravi wrote: > > I'd rather have something along the lines of > .def< mpl::vector >("f1",f1) I have something working. There is still a bunch of stuff to iron out yet. I went with def("name", as(callable)); where Signature is the signature with which callable will be called, e.g. struct times_seven { template struct result; template struct result // annoying: reference { typedef T type; }; template T operator()(const T& t) { return t * 7; } }; BOOST_PYTHON_MODULE( function_objects3_ext ) { def("times_seven", as(times_seven())); } the T& in the struct result is something I haven't yet sorted out, has something to do with how I am constructing fusion sequences from the converted python objects before calling fusion::invoke. Anyhow, it works: >>> times_seven(7) 49 I thought that one might try to remove the necessity of having the return type in the Signature and/or implementing the result_of protocol, but maybe it is nice that they don't have to match: def("times_seven", as(times_seven())); >>> times_seven(7) 49.0 boost::function still works, and doesn't require as<>: boost::function myplus = std::plus(); def("myplus", myplus); and old-school function objects: def("otherplus", std::plus()) I was surprised to find that it all plays nice with boost::phoenix: def("plus", as(arg1 + arg2)); def("throw_if_gt_5", as(if_(arg1 > 5) [ throw_(std::runtime_error("too big!!")) ] .else_ [ std::cout << val("okay") ])); And boost::phoenix plays nice with shared_ptr, which plays nice with boost::python: struct X { int x; }; typedef boost::shared_ptr XPtr; class_("X") .def_readwrite("x", &X::x) .def("add7", as (arg1->*&X::x += 7)) .def("add8", as(arg1->*&X::x += 8)) .def("add9", as (bind(&X::x, arg1) += 9)) ; the other little thing is overload resolution, for which I propose a little helper function "unload" (underload? deload? resolve? I dunno): void foo(int); void foo(double); def("foo", unload(foo)); Which is safer than def("foo", (void(*)(int)) foo); and just as safe as, and less verbose than void(*fooint)(int) = foo; def("foo", fooint); So that's where I'm at... what do you make of that interface? -t From micdestefano at gmail.com Mon Oct 19 17:34:35 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Mon, 19 Oct 2009 17:34:35 +0200 Subject: [C++-sig] Help with converters ... Message-ID: Hello to everyone. I'm stuck with this problem. I'm trying to write a "from Python converter", from a tuple(tuple,tuple) type to C++. Clarifying more, the Python type is a tuple, containing 2 tuples. Now, when I try to implement the "convertible" static member function of the converter class, I write this (I've extracted only the interesting part): static void* convertible(PyObject* obj_ptr) { using namespace boost::python; handle<> hndl(borrowed(obj_ptr)); object in(hndl); if (!PyTuple_Check(in.ptr())) return NULL; extract get_tup0(in[0]), get_tup1(in[1]); bool t1 = get_tup0.check(), t2 = get_tup1.check(); ...... the rest of the code is not necessary .... The problem is that even if I pass a tuple containing two tuples from Python, t1 and t2 become "false". Surely I'm not interfacing properly with Python, but I don't understand why. Can someone help me to understand ? Thank you in advance. Michele -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From hans_meine at gmx.net Mon Oct 19 20:44:30 2009 From: hans_meine at gmx.net (Hans Meine) Date: Mon, 19 Oct 2009 20:44:30 +0200 Subject: [C++-sig] Help with converters ... In-Reply-To: References: Message-ID: <200910192044.39774.hans_meine@gmx.net> Hi Michele! On Montag 19 Oktober 2009, Michele De Stefano wrote: > Now, when I try to implement the "convertible" static member function > of the converter class, I write this (I've extracted only the > interesting part): > > [...] > extract > get_tup0(in[0]), > get_tup1(in[1]); This looks like the problem to me; you're effectively trying to get a *reference* from python, i.e. this can only work if there is already an *existing* boost::python::tuple object hidden in (in[0]) and (in[1]). (This will typically only work with BPL-exported C++ objects wrapped into their python shells.) I'd try simply removing the const &: extract.. -- Ciao, / / .o. /--/ ..o / / ANS ooo -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: This is a digitally signed message part. URL: From micdestefano at gmail.com Tue Oct 20 09:15:21 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Tue, 20 Oct 2009 09:15:21 +0200 Subject: [C++-sig] Help with converters ... In-Reply-To: <200910192044.39774.hans_meine@gmx.net> References: <200910192044.39774.hans_meine@gmx.net> Message-ID: Hans, thank you very much. Removing the substituting "const tuple&" with "tuple" works. Just to let me understand more your answer, what does it mean "BPL-exported" ? I'm not so comfortable with acronyms ... 2009/10/19 Hans Meine : > Hi Michele! > > On Montag 19 Oktober 2009, Michele De Stefano wrote: >> Now, when I try to implement the "convertible" static member function >> of the converter class, I write this (I've extracted only the >> interesting part): >> >> [...] >> ? ? ? extract >> ? ? ? ? ? ? ?get_tup0(in[0]), >> ? ? ? ? ? ? ?get_tup1(in[1]); > > This looks like the problem to me; you're effectively trying to get a > *reference* from python, i.e. this can only work if there is already an > *existing* boost::python::tuple object hidden in (in[0]) and (in[1]). > (This will typically only work with BPL-exported C++ objects wrapped into > their python shells.) > > I'd try simply removing the const &: extract.. > > -- > Ciao, / ?/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.o. > ? ? /--/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ..o > ? ?/ ?/ ANS ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?ooo > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From nitroamos at gmail.com Thu Oct 22 21:13:21 2009 From: nitroamos at gmail.com (Amos Anderson) Date: Thu, 22 Oct 2009 12:13:21 -0700 Subject: [C++-sig] How to install extensions using bjam(?) Message-ID: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> Hello -- I'm working on a project which is mixed C++/Python, and we use Boost functionality in our C++, and we've set up bjam to compile our project (on OSX). Everything seems to be working quite well. To use our libraries from python scripts right now, we have to run this first: #!/bin/bash trunk=$HOME/project/trunk/ export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$trunk/lib export PYTHONPATH=$trunk:$trunk/lib python $@ which is quite inconvenient. Now obviously I can skip this step by pasting those two export statements into my .profile, however, at some point we're going to start distributing this software and it would be nice if we didn't require the end user to do something like that. I can't believe that either of these 2 steps are how it's supposed to work... so how should I be doing it? Ideally, I want to set something up so that the end user only has to run 1 (one) command to build & install. Here are some things I've thought about: 1) Having bjam edit the user's .profile to set up these paths, possibly by calling a script I write. This doesn't seem like the right approach to me. 2) It looks like python's distutils is supposed to be able to help, but it seems like a waste of time to figure out how to get distutils to compile my code when I already have bjam pretty much figured out. First, I assume that distutils can put my libraries on an automatic DYLD_LIBRARY_PATH path that python knows about, because if it can't then there's no point. But assuming that's not a problem, I can't figure out how to tell distutils about Extensions that it shouldn't try to build... 3) bjam includes a way to install libraries into a folder I can name, but does it have a way to set environment variables? or automatically figure out the right places to put all the python files? If so, I can't find it... 4) ? thanks! Amos. From nat at lindenlab.com Thu Oct 22 21:48:09 2009 From: nat at lindenlab.com (Nat Goodspeed) Date: Thu, 22 Oct 2009 15:48:09 -0400 Subject: [C++-sig] How to install extensions using bjam(?) In-Reply-To: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> References: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> Message-ID: <4AE0B6F9.2040705@lindenlab.com> Amos Anderson wrote: > I'm working on a project which is mixed C++/Python, and we use Boost > functionality in our C++, and we've set up bjam to compile our project > (on OSX). Everything seems to be working quite well. > > 2) It looks like python's distutils is supposed to be able to help, > but it seems like a waste of time to figure out how to get distutils > to compile my code when I already have bjam pretty much figured out. > First, I assume that distutils can put my libraries on an automatic > DYLD_LIBRARY_PATH path that python knows about, because if it can't > then there's no point. But assuming that's not a problem, I can't > figure out how to tell distutils about Extensions that it shouldn't > try to build... In a previous project I've had success with py2app: http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html We had a number of extensions we built ourselves (not with distutils or py2app itself) and it happily packaged them into a working app bundle. From micdestefano at gmail.com Fri Oct 23 10:38:30 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Fri, 23 Oct 2009 10:38:30 +0200 Subject: [C++-sig] Python converters for raw pointers: request for help Message-ID: Hello to everyone. I'm trying to write "from Python" converters for PETSc objects of the petsc4py package. Even if no-one of you uses petsc4py, I think you can help me, if I explain some basics. Please, be patient. I want to make converters for the PETSc Mat type. Mat is defined as below: typedef struct _p_Mat* Mat; where _p_Mat is a structure whose details are not interesting for my problem. Now, I managed to make a functioning "to Python converter". My problem is the "from Python converter". I made a test function void print_Mat(Mat m) { ... // The implementation is not interesting }; And I tried to make a "from Python converter" with the code below (please, look at it ... it's not too long and it's very simple): struct PETSc_Mat_from_Python { PETSc_Mat_from_Python() { static bool do_registration(true); if (do_registration) { boost::python::converter::registry::push_back( &convertible,&construct,boost::python::type_id()); do_registration = false; } } static void* convertible(PyObject* obj_ptr) { // In the line below, PyPetscMat_Get takes a PyObject* as input and returns a Mat // (if it succedes) or a PETSC_NULL (if it fails). This is a function of the petsc4py C API. // The ownership of the returned Mat is not transferred (I think) if (PyPetscMat_Get(obj_ptr) == PETSC_NULL) return NULL; return obj_ptr; } static void construct(PyObject* obj_ptr, boost::python::converter::rvalue_from_python_stage1_data* data) { void* storage = ( (boost::python::converter:: rvalue_from_python_storage*)data)->storage.bytes; data->convertible = storage; // NOTE: The instruction below does not transfer ownership, but this is not my problem, for now new (storage) Mat(PyPetscMat_Get(obj_ptr)); } }; Then, obviously ... BOOST_PYTHON_MODULE(petsc_ext) { ... some not important lines ... PETSc_Mat_from_Python(); // Registers the converter def("print_Mat",print_Mat); } The code compiles without errors. The problem is that when calling "print_Mat" from the Python shell, the interpreter gives the error: print_Mat(m) # where m was previously and correctly built from Python and it is a Python object containing a Mat Traceback (most recent call last): File "", line 1, in ? Boost.Python.ArgumentError: Python argument types in petsc_ext.print_Mat(petsc4py.PETSc.Mat) did not match C++ signature: print_Mat(_p_Mat*) I tried also to modify "void print_Mat(Mat m)" into "void print_Mat(const Mat m)" or "void print_Mat(const Mat& m)", but the result is the same. I tried also to debug the code, but the debugger does not enter into the "convertible" method, so I guess there is something wrong that I can't see. So may be I am missing something for the process of writing a "from Python converter" for pointer arguments. Can anyone help me, please ? -- Michele De Stefano http://www.linkedin.com/in/micdestefano From rfritz333 at gmail.com Mon Oct 26 01:26:24 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Mon, 26 Oct 2009 00:26:24 +0000 (UTC) Subject: [C++-sig] Python converters for raw pointers: request for help References: Message-ID: Do you want to return an opaque type, would you like to expose some of the mat's methods in Python, or would you perhaps like to convert a numpy Matrix to a PETSc mat? These all take different approaches. Could you perhaps give an example of some of the Python code you would like to write? -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From rfritz333 at gmail.com Mon Oct 26 01:32:15 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Mon, 26 Oct 2009 00:32:15 +0000 (UTC) Subject: [C++-sig] Python converters for raw pointers: request for help References: Message-ID: Additional thought. Take a look at: & see if it helps clarify some of the problems. -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From micdestefano at gmail.com Mon Oct 26 09:29:50 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Mon, 26 Oct 2009 09:29:50 +0100 Subject: [C++-sig] Python converters for raw pointers: request for help In-Reply-To: References: Message-ID: Ok. Let me clarify (I looked at the link you suggested, but I've not found the answers I was looking for). There exist a "petsc4py" package, which can be extended using its C API. This package, already exposes PETSc types (and also the Mat type). petsc4py is not programmed using Boost Python. Now, assume I already have a C++ function that takes a Mat parameter; to make it simple, let's take void print_Mat(Mat m) { ... // The implementation is not interesting }; I'd like to expose this function to Python, with a seamless integration mechanism, using Boost Python. Unfortunately, if I use the petsc4py API, I have to expose a wrapper for "print_Mat", in this way: void print_Mat_Wrap(const object& mat_obj) { Mat m( PyPetscMat_Get(mat_obj.ptr()) ); ... // The rest is not important } I don't know anything of the petsc4py implementation, but I know that it already exposes PETSc Mat to Python. I know also that, using the petsc4py C API, the only way to retrieve a Mat from a PyObject* is through the PyPetscMat_Get function, whose signature is this one: Mat (*PyPetscMat_Get)(PyObject *); I know for sure that Mat objects are not allocated with the C++ new operator (I don't know if this is a useful information for you). What I'd really like to do, would be to write a from-Python-converter from a PyObject* (containing a petsc4py exposed Mat) into a Mat, in order to be able to directly expose my "void print_Mat(Mat m)" without writing any wrapper ... but I didn't manage to properly make it ... Is this possible ? 2009/10/26 Randolph Fritz : > Additional thought. ?Take a look at: > ? > & see if it helps clarify some of the problems. > > -- > Randolph Fritz > ?design machine group, architecture department, university of washington > rfritz at u.washington.edu -or- rfritz333 at gmail.com > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From micdestefano at gmail.com Mon Oct 26 09:38:41 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Mon, 26 Oct 2009 09:38:41 +0100 Subject: [C++-sig] Python converters for raw pointers: request for help In-Reply-To: References: Message-ID: I was forgetting to give an example of the Python code I would like to write: >>> from petsc4py import PETSc ... now some uninteresting code for building a PETSc.Mat python object ... ... the result will be a PETSc.Mat m object .... ... once created, if I write "m" and press RETURN, this is the output ... >>> m ... so, basically, I already have a PETSc Mat in Python, because it is exposed by the petsc4py package ... ... Now I want to pass this Python object to my "print_Mat" function ... ... What I'd like to write is ... >>> form my_extension import * >>> print_Mat(m) I hope now it's all clear. Thank you in advance. Michele 2009/10/26 Michele De Stefano : > Ok. Let me clarify (I looked at the link you suggested, but I've not > found the answers I was looking for). > > There exist a "petsc4py" package, which can be extended using its C > API. This package, already exposes PETSc types (and also the Mat > type). petsc4py is not programmed using Boost Python. > > Now, assume I already have a C++ function that takes a Mat parameter; > to make it simple, let's take > > void print_Mat(Mat m) { > ? ... // The implementation is not interesting > }; > > I'd like to expose this function to Python, with a seamless > integration mechanism, using Boost Python. > > Unfortunately, if I use the petsc4py API, I have to expose a wrapper > for "print_Mat", in this way: > > void print_Mat_Wrap(const object& mat_obj) { > ? ?Mat m( PyPetscMat_Get(mat_obj.ptr()) ); > ? ?... // The rest is not important > } > > I don't know anything of the petsc4py implementation, but I know that > it already exposes PETSc Mat to Python. I know also that, using the > petsc4py C API, the only way to retrieve a Mat from a > PyObject* is through the PyPetscMat_Get function, whose signature is this one: > > Mat (*PyPetscMat_Get)(PyObject *); > > I know for sure that Mat objects are not allocated with the C++ new > operator (I don't know if this is a useful information for you). > > What I'd really like to do, would be to write a from-Python-converter > from a PyObject* (containing a petsc4py exposed Mat) into a Mat, in > order to be able to directly expose my "void print_Mat(Mat m)" without > writing any wrapper ... but I didn't manage to properly make it ... > > Is this possible ? > > > 2009/10/26 Randolph Fritz : >> Additional thought. ?Take a look at: >> ? >> & see if it helps clarify some of the problems. >> >> -- >> Randolph Fritz >> ?design machine group, architecture department, university of washington >> rfritz at u.washington.edu -or- rfritz333 at gmail.com >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > > -- > Michele De Stefano > http://www.linkedin.com/in/micdestefano > http://xoomer.virgilio.it/michele_de_stefano > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From AFoglia at princeton.com Mon Oct 26 15:08:16 2009 From: AFoglia at princeton.com (Anthony Foglia) Date: Mon, 26 Oct 2009 10:08:16 -0400 Subject: [C++-sig] How to install extensions using bjam(?) In-Reply-To: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> References: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> Message-ID: <4AE5AD50.6010009@princeton.com> Amos Anderson wrote: > I'm working on a project which is mixed C++/Python, and we use Boost > functionality in our C++, and we've set up bjam to compile our project > (on OSX). Everything seems to be working quite well. > > To use our libraries from python scripts right now, we have to run this first: > > #!/bin/bash > trunk=$HOME/project/trunk/ > export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$trunk/lib > export PYTHONPATH=$trunk:$trunk/lib > python $@ > > > which is quite inconvenient. Now obviously I can skip this step by > pasting those two export statements into my .profile, however, at some > point we're going to start distributing this software and it would be > nice if we didn't require the end user to do something like that. > > I can't believe that either of these 2 steps are how it's supposed to > work... so how should I be doing it? Ideally, I want to set something > up so that the end user only has to run 1 (one) command to build & > install. Here are some things I've thought about: [...] > 3) bjam includes a way to install libraries into a folder I can name, > but does it have a way to set environment variables? or automatically > figure out the right places to put all the python files? If so, I > can't find it... Almost certainly not. bjam would be running in a child process and won't be able to change the environment of the parent (shell) process. Even if it did, any changes wouldn't persist into newly launched shells. I don't think there you can get the "right place" to put the python files, especially since different users will have different "right places". I think your best bet is to follow the usual convention of using a default location of "/usr/lib/python/site-packages", but allow users to override it from the command line. I'm not 100% sure of the syntax, but something like bjam -s prefix=/usr/local/lib/python2.5 should set the variable prefix to /usr/local/lib/python2.5 inside the Jamfile. Now you just need a way to get the default python version to set the default value. bjam's python module has a .version-countdown variable that might help. The boost-build mailing list can probably give you better help. -- Anthony Foglia Princeton Consultants (609) 987-8787 x233 From micdestefano at gmail.com Mon Oct 26 17:28:57 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Mon, 26 Oct 2009 17:28:57 +0100 Subject: [C++-sig] How to call reshape((M,N),order='F') ? Message-ID: Hello to everyone. I have this problem. Assume I'm building a to-Python converter for a 3x2 matrix type, FORTRAN storage (these are not the real dimensions of my problem, but I give these numbers only to simplify the discussion). Into the "convert" C++ method, first, I build a list with all the matrix elements (lout); then, I instantiate a boost::python::numeric::array in this way (note: I had previously used set_module_and_type("numpy","ndarray"), for using the NumPy's array): boost::python::numeric::array v(lout) Finally, I'd like to call "reshape" on this array, in this way v.attr("reshape")(make_tuple(3,2),"F"); But it does not work. It builds, but, on runtime, I obtain the error: Traceback (most recent call last): File "", line 1, in ? TypeError: an integer is required I tried to build and re-shape a matrix entirely from Python and I discovered that, when using reshape, you are forced to give the second parameter as order = 'C' or 'F' Now the question is: is it possible to specify a named parameter from the C++ code ? If the answer is "yes", how ? Thank you in advance, Michele -- Michele De Stefano http://www.linkedin.com/in/micdestefano From eilif at gmx.de Mon Oct 26 18:01:49 2009 From: eilif at gmx.de (Eilif Mueller) Date: Mon, 26 Oct 2009 18:01:49 +0100 Subject: [C++-sig] function with >15 args yields get_signature error Message-ID: <20091026170149.143750@gmx.net> Hi, Wrapping a function f with 16 arguments: int f(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16) { return x1; } BOOST_PYTHON_MODULE(test) { def("f",f); } yields /usr/include/boost/python/make_function.hpp: In function ?boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]?: /usr/include/boost/python/def.hpp:82: instantiated from ?boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? /usr/include/boost/python/def.hpp:91: instantiated from ?void boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? test_module.cpp:20: instantiated from here /usr/include/boost/python/make_function.hpp:104: error: no matching function for call to ?get_signature(int (*&)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int))? make: *** [stream.o] Error 1 whereas all is fine if that last arg "int x16" is removed. All of gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. Same effect for libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on Ubuntu jaunty. I need that 16th arg and more ... about 32 args, I think. Thanks for any help you can offer. cheers, Eilif -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser From troy at resophonic.com Mon Oct 26 18:08:42 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 26 Oct 2009 13:08:42 -0400 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <20091026170149.143750@gmx.net> References: <20091026170149.143750@gmx.net> Message-ID: <4AE5D79A.6040505@resophonic.com> Eilif Mueller wrote: > Hi, > > Wrapping a function f with 16 arguments: > > int f(int x1, int x2, int x3, int x4, int x5, > int x6, int x7, int x8, int x9, int x10, > int x11, int x12, int x13, int x14, int x15, > int x16) { > > return x1; > > } > > BOOST_PYTHON_MODULE(test) > { > > def("f",f); > > } > > > yields > > /usr/include/boost/python/make_function.hpp: In function ?boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]?: > /usr/include/boost/python/def.hpp:82: instantiated from ?boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? > /usr/include/boost/python/def.hpp:91: instantiated from ?void boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? > test_module.cpp:20: instantiated from here > /usr/include/boost/python/make_function.hpp:104: error: no matching function for call to ?get_signature(int (*&)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int))? > make: *** [stream.o] Error 1 > > > whereas all is fine if that last arg "int x16" is removed. All of gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. Same effect for libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on Ubuntu jaunty. > > I need that 16th arg and more ... about 32 args, I think. > > Thanks for any help you can offer. > This came up recently. You're going to have various problems (not all boost.python problems) getting arity that large. The workaround is to introduce an intermediate function that takes a boost::python::tuple and forward to the zillion-arguments one, example here: http://gitorious.org/~straszheim/boost/straszheim/blobs/python/libs/python/test/zillion_arguments_workaround.cpp -t From renatox at gmail.com Mon Oct 26 18:21:22 2009 From: renatox at gmail.com (Renato Araujo) Date: Mon, 26 Oct 2009 14:21:22 -0300 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <20091026170149.143750@gmx.net> References: <20091026170149.143750@gmx.net> Message-ID: <95291a80910261021i7b1eaad3i64f1fbc9c180c69d@mail.gmail.com> Hi, Try use this flag in your compilation, -DBOOST_PYTHON_MAX_ARITY=XX The default value is 15, the I think thi can solve your problem. BR Renato Araujo Oliveira Filho On Mon, Oct 26, 2009 at 2:01 PM, Eilif Mueller wrote: > Hi, > > Wrapping a function f with 16 arguments: > > int f(int x1, int x2, int x3, int x4, int x5, > ? ? ?int x6, int x7, int x8, int x9, int x10, > ? ? ?int x11, int x12, int x13, int x14, int x15, > ? ? ?int x16) { > > ?return x1; > > } > > BOOST_PYTHON_MODULE(test) > { > > ?def("f",f); > > } > > > yields > > /usr/include/boost/python/make_function.hpp: In function ?boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]?: > /usr/include/boost/python/def.hpp:82: ? instantiated from ?boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? > /usr/include/boost/python/def.hpp:91: ? instantiated from ?void boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]? > test_module.cpp:20: ? instantiated from here > /usr/include/boost/python/make_function.hpp:104: error: no matching function for call to ?get_signature(int (*&)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int))? > make: *** [stream.o] Error 1 > > > whereas all is fine if that last arg "int x16" is removed. ?All of gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. ?Same effect for libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on Ubuntu jaunty. > > I need that 16th arg and more ... about 32 args, I think. > > Thanks for any help you can offer. > > cheers, > > Eilif > > > > > > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From wladwig at wdtinc.com Mon Oct 26 18:20:14 2009 From: wladwig at wdtinc.com (William Ladwig) Date: Mon, 26 Oct 2009 12:20:14 -0500 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <20091026170149.143750@gmx.net> References: <20091026170149.143750@gmx.net> Message-ID: <765CBD9053EA2B438625895F30D1856F02DC395454@storm.wdtinc.com> There is a config macro BOOST_PYTHON_MAX_ARITY which may work for you. I'm not sure how high you can increase this number though. Refer to: http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/configuration.html -----Original Message----- From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Eilif Mueller Sent: Monday, October 26, 2009 12:02 PM To: cplusplus-sig at python.org Subject: [C++-sig] function with >15 args yields get_signature error Hi, Wrapping a function f with 16 arguments: int f(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16) { return x1; } BOOST_PYTHON_MODULE(test) { def("f",f); } yields /usr/include/boost/python/make_function.hpp: In function 'boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]': /usr/include/boost/python/def.hpp:82: instantiated from 'boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]' /usr/include/boost/python/def.hpp:91: instantiated from 'void boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)]' test_module.cpp:20: instantiated from here /usr/include/boost/python/make_function.hpp:104: error: no matching function for call to 'get_signature(int (*&)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int))' make: *** [stream.o] Error 1 whereas all is fine if that last arg "int x16" is removed. All of gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. Same effect for libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on Ubuntu jaunty. I need that 16th arg and more ... about 32 args, I think. Thanks for any help you can offer. cheers, Eilif -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From nitroamos at gmail.com Mon Oct 26 19:11:37 2009 From: nitroamos at gmail.com (Amos Anderson) Date: Mon, 26 Oct 2009 11:11:37 -0700 Subject: [C++-sig] How to install extensions using bjam(?) In-Reply-To: <4AE5AD50.6010009@princeton.com> References: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> <4AE5AD50.6010009@princeton.com> Message-ID: <9e910970910261111qe312a9ai1d1f16be387477f6@mail.gmail.com> On Mon, Oct 26, 2009 at 7:08 AM, Anthony Foglia wrote: > Amos Anderson wrote: >> >> I'm working on a project which is mixed C++/Python, and we use Boost >> functionality in our C++, and we've set up bjam to compile our project >> (on OSX). Everything seems to be working quite well. >> >> To use our libraries from python scripts right now, we have to run this >> first: >> >> #!/bin/bash >> trunk=$HOME/project/trunk/ >> export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$trunk/lib >> export PYTHONPATH=$trunk:$trunk/lib >> python $@ >> >> >> which is quite inconvenient. Now obviously I can skip this step by >> pasting those two export statements into my .profile, however, at some >> point we're going to start distributing this software and it would be >> nice if we didn't require the end user to do something like that. >> >> I can't believe that either of these 2 steps are how it's supposed to >> work... so how should I be doing it? ?Ideally, I want to set something >> up so that the end user only has to run 1 (one) command to build & >> install. Here are some things I've thought about: > > [...] > >> 3) bjam includes a way to install libraries into a folder I can name, >> but does it have a way to set environment variables? or automatically >> figure out the right places to put all the python files? If so, I >> can't find it... > > ? ? ? ?Almost certainly not. ?bjam would be running in a child process and > won't be able to change the environment of the parent (shell) process. Even > if it did, any changes wouldn't persist into newly launched shells. Well, what I had in mind was getting bjam to implement my solution #1. So bjam would scan my .profile to see if it had ever modified the file previously, and if so modify previously set variables, otherwise add new environmental variables, etc. > > ? ? ? ?I don't think there you can get the "right place" to put the python > files, especially since different users will have different "right places". > ?I think your best bet is to follow the usual convention of using a default > location of "/usr/lib/python/site-packages", but allow users to > override it from the command line. ?I'm not 100% sure of the syntax, but > something like > > bjam -s prefix=/usr/local/lib/python2.5 > > should set the variable prefix to /usr/local/lib/python2.5 inside the > Jamfile. > > Now you just need a way to get the default python version to set the default > value. ?bjam's python module has a .version-countdown variable that might > help. Based on your idea, I did some searching, and I found that I can do this: python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" /Library/Python/2.6/site-packages to automatically find the right location. And, it looks like: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/dyld.1.html says I can put the dylib's in one of these places: $(HOME)/lib:/usr/local/lib:/lib:/usr/lib and the linker will automatically find them. I guess one of those is good enough for me, but I'd imagine that python would add a few new places to look? I tried to put my dylib files into site-packages, but that didn't work. It looks like this is making some progress. It looks like at the very least I can get bjam to put the dylib into $(HOME)/lib directly, and edit the python scripts to add the right python paths. Amos. > > The boost-build mailing list can probably give you better help. > I've tried a few times to sign up to that list... but it doesn't seem to work. thanks! Amos. > -- > Anthony Foglia > Princeton Consultants > (609) 987-8787 x233 > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- ~<>~<>~<>~<>~<>~<>~<>~<>~ nitroamos at gmail.com amosa at wag.caltech.edu (secure) +1-626-399-8958 (cell) +1-626-794-1971 (home) From AFoglia at princeton.com Mon Oct 26 19:52:47 2009 From: AFoglia at princeton.com (Anthony Foglia) Date: Mon, 26 Oct 2009 14:52:47 -0400 Subject: [C++-sig] How to install extensions using bjam(?) In-Reply-To: <9e910970910261111qe312a9ai1d1f16be387477f6@mail.gmail.com> References: <9e910970910221213j5b3d5a73xcc4d34fddc095ca4@mail.gmail.com> <4AE5AD50.6010009@princeton.com> <9e910970910261111qe312a9ai1d1f16be387477f6@mail.gmail.com> Message-ID: <4AE5EFFF.1050505@princeton.com> Amos Anderson wrote: > Well, what I had in mind was getting bjam to implement my solution #1. > So bjam would scan my .profile to see if it had ever modified the file > previously, and if so modify previously set variables, otherwise add > new environmental variables, etc. But what if the user isn't using bash, but tcsh? Or if they have a .bash_profile? Or if they source their .bashrc via their .profile and set their PYTHONPATH in there? There's a lot that could go wrong. The second approach sounds much more robust and is the more conventional approach. Hopefully you can get it to do what you want. -- Anthony Foglia Princeton Consultants (609) 987-8787 x233 From rfritz333 at gmail.com Mon Oct 26 20:10:55 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Mon, 26 Oct 2009 19:10:55 +0000 (UTC) Subject: [C++-sig] Python converters for raw pointers: request for help References: Message-ID: I think what you want is here: and here: Take a look at that--see if it helps. -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From eilif at gmx.de Mon Oct 26 21:59:13 2009 From: eilif at gmx.de (Eilif Mueller) Date: Mon, 26 Oct 2009 21:59:13 +0100 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <765CBD9053EA2B438625895F30D1856F02DC395454@storm.wdtinc.com> References: <20091026170149.143750@gmx.net> <765CBD9053EA2B438625895F30D1856F02DC395454@storm.wdtinc.com> Message-ID: <20091026205913.294100@gmx.net> Hi, Thanks! -DBOOST_PYTHON_MAX_ARITY=34 did indeed help ... for simple functions it did the trick, and it did increase my limit for member functions, but only to 25. For over 25 args for a member functions of an exposed class I get the following compiler error: /usr/include/boost/python/detail/invoke.hpp:81: error: must use ?.*? or ?->*? to call pointer-to-member function in ?f (...)? #include using namespace boost::python; class MyClass { public: int qq(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20, int x21, int x22, int x23, int x24, float x25 /*,float x26*/); }; BOOST_PYTHON_MODULE(mytest) { class_< MyClass >("MyClass", init<>() ) .def("qq",&MyClass::qq); } Any ideas? cheers, Eilif -------- Original-Nachricht -------- > Datum: Mon, 26 Oct 2009 12:20:14 -0500 > Von: William Ladwig > An: Development of Python/C++ integration > Betreff: Re: [C++-sig] function with >15 args yields get_signature error > There is a config macro BOOST_PYTHON_MAX_ARITY which may work for you. > I'm not sure how high you can increase this number though. Refer to: > > http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/configuration.html > > > > -----Original Message----- > From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org > [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Eilif Mueller > Sent: Monday, October 26, 2009 12:02 PM > To: cplusplus-sig at python.org > Subject: [C++-sig] function with >15 args yields get_signature error > > Hi, > > Wrapping a function f with 16 arguments: > > int f(int x1, int x2, int x3, int x4, int x5, > int x6, int x7, int x8, int x9, int x10, > int x11, int x12, int x13, int x14, int x15, > int x16) { > > return x1; > > } > > BOOST_PYTHON_MODULE(test) > { > > def("f",f); > > } > > > yields > > /usr/include/boost/python/make_function.hpp: In function > 'boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, > int, int, int, int, int, int, int, int, int, int, int, int, int)]': > /usr/include/boost/python/def.hpp:82: instantiated from > 'boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int > (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, > int)]' > /usr/include/boost/python/def.hpp:91: instantiated from 'void > boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, > int, int, int, int, int, int, int, int, int, int)]' > test_module.cpp:20: instantiated from here > /usr/include/boost/python/make_function.hpp:104: error: no matching > function for call to 'get_signature(int (*&)(int, int, int, int, int, int, int, > int, int, int, int, int, int, int, int, int))' > make: *** [stream.o] Error 1 > > > whereas all is fine if that last arg "int x16" is removed. All of > gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. Same effect for > libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on > Ubuntu jaunty. > > I need that 16th arg and more ... about 32 args, I think. > > Thanks for any help you can offer. > > cheers, > > Eilif > > > > > > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 > - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 > - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > _______________________________________________ > 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 -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser From craig.bosma at gmail.com Mon Oct 26 22:03:20 2009 From: craig.bosma at gmail.com (Craig S. Bosma) Date: Mon, 26 Oct 2009 16:03:20 -0500 Subject: [C++-sig] RuntimeError on import from use of bases<> Message-ID: <03DA9677-860D-4D33-B6FD-AEF598CEC391@gmail.com> Hi, I'm having a difficult time debugging an issue with boost.python bindings under OS X 10.6 -- the same bindings have been working fine under windows. On import of my module, I get an exception caught by python: > RuntimeError: unidentifiable C++ exception which I've traced down as far as the use of a bases<> entry in my class_ definition. If I remove the bases<> entry, it works, but of course removing all inheiritance from the module isn't an option. Furthermore, it seems that any (so far) use of bases<> in this module causes the problem, while in another module (wrapping another library) classes deriving from others via bases<> work normally. Any thoughts on what could case this type of failure? Craig From Matthew.Scouten at tradingtechnologies.com Mon Oct 26 22:03:18 2009 From: Matthew.Scouten at tradingtechnologies.com (Matthew Scouten (TT)) Date: Mon, 26 Oct 2009 16:03:18 -0500 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <20091026205913.294100@gmx.net> References: <20091026170149.143750@gmx.net><765CBD9053EA2B438625895F30D1856F02DC395454@storm.wdtinc.com> <20091026205913.294100@gmx.net> Message-ID: <32490DFF7774554A85D65D23A9F0F9380BAC6C8B@chiex01> Yeah. Find the guy who wrote a function with over 25 arguments. Bring a baseball bat. Persuade him of his error. -----Original Message----- From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org] On Behalf Of Eilif Mueller Sent: Monday, October 26, 2009 3:59 PM To: Development of Python/C++ integration Subject: Re: [C++-sig] function with >15 args yields get_signature error Hi, Thanks! -DBOOST_PYTHON_MAX_ARITY=34 did indeed help ... for simple functions it did the trick, and it did increase my limit for member functions, but only to 25. For over 25 args for a member functions of an exposed class I get the following compiler error: /usr/include/boost/python/detail/invoke.hpp:81: error: must use ?.*? or ?->*? to call pointer-to-member function in ?f (...)? #include using namespace boost::python; class MyClass { public: int qq(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20, int x21, int x22, int x23, int x24, float x25 /*,float x26*/); }; BOOST_PYTHON_MODULE(mytest) { class_< MyClass >("MyClass", init<>() ) .def("qq",&MyClass::qq); } Any ideas? cheers, Eilif -------- Original-Nachricht -------- > Datum: Mon, 26 Oct 2009 12:20:14 -0500 > Von: William Ladwig > An: Development of Python/C++ integration > Betreff: Re: [C++-sig] function with >15 args yields get_signature error > There is a config macro BOOST_PYTHON_MAX_ARITY which may work for you. > I'm not sure how high you can increase this number though. Refer to: > > http://www.boost.org/doc/libs/1_40_0/libs/python/doc/v2/configuration.html > > > > -----Original Message----- > From: cplusplus-sig-bounces+wladwig=wdtinc.com at python.org > [mailto:cplusplus-sig-bounces+wladwig=wdtinc.com at python.org] On Behalf Of Eilif Mueller > Sent: Monday, October 26, 2009 12:02 PM > To: cplusplus-sig at python.org > Subject: [C++-sig] function with >15 args yields get_signature error > > Hi, > > Wrapping a function f with 16 arguments: > > int f(int x1, int x2, int x3, int x4, int x5, > int x6, int x7, int x8, int x9, int x10, > int x11, int x12, int x13, int x14, int x15, > int x16) { > > return x1; > > } > > BOOST_PYTHON_MODULE(test) > { > > def("f",f); > > } > > > yields > > /usr/include/boost/python/make_function.hpp: In function > 'boost::python::api::object boost::python::make_function(F) [with F = int (*)(int, int, int, > int, int, int, int, int, int, int, int, int, int, int, int, int)]': > /usr/include/boost/python/def.hpp:82: instantiated from > 'boost::python::api::object boost::python::detail::make_function1(T, ...) [with T = int > (*)(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, > int)]' > /usr/include/boost/python/def.hpp:91: instantiated from 'void > boost::python::def(const char*, Fn) [with Fn = int (*)(int, int, int, int, int, int, > int, int, int, int, int, int, int, int, int, int)]' > test_module.cpp:20: instantiated from here > /usr/include/boost/python/make_function.hpp:104: error: no matching > function for call to 'get_signature(int (*&)(int, int, int, int, int, int, int, > int, int, int, int, int, int, int, int, int))' > make: *** [stream.o] Error 1 > > > whereas all is fine if that last arg "int x16" is removed. All of > gcc-4.2, gcc-4.3 and gcc-4.4 seem to exhibit the same behaviour. Same effect for > libboost-python1.38-dev on Ubuntu karmic and libboost-python1.35-dev on > Ubuntu jaunty. > > I need that 16th arg and more ... about 32 args, I think. > > Thanks for any help you can offer. > > cheers, > > Eilif > > > > > > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 > - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 > - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > _______________________________________________ > 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 -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org http://mail.python.org/mailman/listinfo/cplusplus-sig From troy at resophonic.com Mon Oct 26 22:30:57 2009 From: troy at resophonic.com (troy d. straszheim) Date: Mon, 26 Oct 2009 17:30:57 -0400 Subject: [C++-sig] function with >15 args yields get_signature error In-Reply-To: <32490DFF7774554A85D65D23A9F0F9380BAC6C8B@chiex01> References: <20091026170149.143750@gmx.net><765CBD9053EA2B438625895F30D1856F02DC395454@storm.wdtinc.com> <20091026205913.294100@gmx.net> <32490DFF7774554A85D65D23A9F0F9380BAC6C8B@chiex01> Message-ID: <4AE61511.4070006@resophonic.com> Matthew Scouten (TT) wrote: > Yeah. Find the guy who wrote a function with over 25 arguments. Bring > a baseball bat. Persuade him of his error. +1. "Clue-by-four" time. > -----Original Message----- From: > cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org > [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org] > On Behalf Of Eilif Mueller Sent: Monday, October 26, 2009 3:59 PM To: > Development of Python/C++ integration Subject: Re: [C++-sig] function > with >15 args yields get_signature error > > Hi, > > Thanks! -DBOOST_PYTHON_MAX_ARITY=34 did indeed help ... for simple > functions it did the trick, and it did increase my limit for member > functions, but only to 25. For over 25 args for a member functions > of an exposed class I get the following compiler error: > > /usr/include/boost/python/detail/invoke.hpp:81: error: must use ?.*? > or ?->*? to call pointer-to-member function in ?f (...)? > I believe this is because BOOST_PYTHON_MAX_ARITY doesn't have the ability to change the hardcoded limit of 25 parameters in boost/type_traits/detail/is_mem_fun_ptr_impl.hpp, which boost.python uses. This is why I recommended that workaround. -t From micdestefano at gmail.com Tue Oct 27 09:10:52 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Tue, 27 Oct 2009 09:10:52 +0100 Subject: [C++-sig] Python converters for raw pointers: request for help In-Reply-To: References: Message-ID: That's not what I'd like to do. I'd like to make a "from-Python" converter. I don't want to make a wrapper that takes a boost::python::object and then call extract ... The problem in my converter (see the previous e-mails) is that Python does not even enter into the "convertible" method ... 2009/10/26 Randolph Fritz : > I think what you want is here: > ? > > and here: > ? > > Take a look at that--see if it helps. > > -- > Randolph Fritz > ?design machine group, architecture department, university of washington > rfritz at u.washington.edu -or- rfritz333 at gmail.com > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From rfritz333 at gmail.com Tue Oct 27 16:39:12 2009 From: rfritz333 at gmail.com (Randolph Fritz) Date: Tue, 27 Oct 2009 15:39:12 +0000 (UTC) Subject: [C++-sig] Python converters for raw pointers: request for help References: Message-ID: On 2009-10-27, Michele De Stefano wrote: > That's not what I'd like to do. I'd like to make a "from-Python" > converter. I don't want to make a wrapper that takes a > boost::python::object and then call extract ... > > The problem in my converter (see the previous e-mails) is that Python > does not even enter into the "convertible" method ... > Hunh. Well, I'm out of ideas, then. Sorry. -- Randolph Fritz design machine group, architecture department, university of washington rfritz at u.washington.edu -or- rfritz333 at gmail.com From micdestefano at gmail.com Wed Oct 28 00:30:32 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Wed, 28 Oct 2009 00:30:32 +0100 Subject: [C++-sig] New mds-utils release (1.2.0) Message-ID: mds-utils 1.2.0 have been released. Release Notes: - Improved python/fileobj.hpp: now there are 3 helper file objects and they are copy-constructible. Derivation from boost::python::object has been mantained. - Added utilities for indexing support in Python extensions. - Added boost::python converters for some boost::numeric::ublas classes. ------------------- What is mds-utils ? ------------------- mds-utils is a library intended to become a collection of several C++ utilities. It makes heavy usage of the Boost C++ libraries. Release 1.2.0 contains: - a tool for detecting machine endianity. - some useful classes that allow to treat the old C FILE pointer as a C++ stream. - C++ classes that help on treating Python file objects as C++ streams. - simple utilities for indexing support in Python extensions. - new C++ to-Python and from-Python converters for some Boost uBlas objects. Project home: http://code.google.com/p/mds-utils/ -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From walter at mathematik.hu-berlin.de Wed Oct 28 20:31:33 2009 From: walter at mathematik.hu-berlin.de (Sebastian Walter) Date: Wed, 28 Oct 2009 20:31:33 +0100 Subject: [C++-sig] How to call reshape((M,N),order='F') ? In-Reply-To: References: Message-ID: <8867253f08604f5750d48ec4c93030f6.squirrel@webmail.mathematik.hu-berlin.de> > Hello to everyone. > > I have this problem. > > Assume I'm building a to-Python converter for a 3x2 matrix type, > FORTRAN storage (these are not the real dimensions of my problem, but > I give these numbers only to simplify the discussion). > > Into the "convert" C++ method, first, I build a list with all the > matrix elements (lout); > then, I instantiate a boost::python::numeric::array in this way (note: > I had previously used > set_module_and_type("numpy","ndarray"), for using the NumPy's array): > > boost::python::numeric::array v(lout) > > Finally, I'd like to call "reshape" on this array, in this way > > v.attr("reshape")(make_tuple(3,2),"F"); don't know the answer to your question, but you could do the following: set the strides of the underlying PyArrayObject manually to match column major format, i.e. PyArrayObject *v_array_obj = reinterpret_cast ( v.ptr() ); v_array_obj->strides[0] = sizeof(double); v_array_obj->strides[1] = 3 * sizeof(double); hope that helps, Sebastian > > But it does not work. It builds, but, on runtime, I obtain the error: > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: an integer is required > > I tried to build and re-shape a matrix entirely from Python and I > discovered that, when using reshape, > you are forced to give the second parameter as > > order = 'C' or 'F' > > Now the question is: is it possible to specify a named parameter from > the C++ code ? > If the answer is "yes", how ? > > Thank you in advance, > Michele > > -- > Michele De Stefano > http://www.linkedin.com/in/micdestefano > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Sebastian Walter Institut fuer Mathematik, Humboldt-Universitaet Tel: +49 (30) 2093-5869 Rudower Chaussee 25, Adlershof, Berlin Fax: +49 (30) 2093-5859 Post: Unter den Linden 6, D-10099 Berlin Email: walter at mathematik.hu-berlin.de WWW: http://www.mathematik.hu-berlin.de/~walter From micdestefano at gmail.com Thu Oct 29 08:58:11 2009 From: micdestefano at gmail.com (Michele De Stefano) Date: Thu, 29 Oct 2009 08:58:11 +0100 Subject: [C++-sig] How to call reshape((M,N),order='F') ? In-Reply-To: <8867253f08604f5750d48ec4c93030f6.squirrel@webmail.mathematik.hu-berlin.de> References: <8867253f08604f5750d48ec4c93030f6.squirrel@webmail.mathematik.hu-berlin.de> Message-ID: Thank you Sebastian. I discovered also that the problem could be solved using the global numpy.reshape. That function, does not complain if the last parameter is simply "F" and not "storage=F". Anyway the issue is still open. If anyone knows it, is it possible to explicitly specify a named parameter through a call to "attr" ? 2009/10/28 Sebastian Walter : > >> Hello to everyone. >> >> I have this problem. >> >> Assume I'm building a to-Python converter for a 3x2 matrix type, >> FORTRAN storage (these are not the real dimensions of my problem, but >> I give these numbers only to simplify the discussion). >> >> Into the "convert" C++ method, first, I build a list with all the >> matrix elements (lout); >> then, I instantiate a boost::python::numeric::array in this way (note: >> I had previously used >> set_module_and_type("numpy","ndarray"), for using the NumPy's array): >> >> boost::python::numeric::array ? v(lout) >> >> Finally, I'd like to call "reshape" on this array, in this way >> >> v.attr("reshape")(make_tuple(3,2),"F"); > > don't know the answer to your question, but you could do the following: > > set the strides of the underlying PyArrayObject manually to match column > major format, i.e. > PyArrayObject ?*v_array_obj = reinterpret_cast ( v.ptr() ); > v_array_obj->strides[0] = sizeof(double); > v_array_obj->strides[1] = 3 * sizeof(double); > > hope that helps, > > Sebastian > > >> >> But it does not work. It builds, but, on runtime, I obtain the error: >> >> Traceback (most recent call last): >> ? File "", line 1, in ? >> TypeError: an integer is required >> >> I tried to build and re-shape a matrix entirely from Python and I >> discovered that, when using reshape, >> you are forced to give the second parameter as >> >> order = 'C' or 'F' >> >> Now the question is: is it possible to specify a named parameter from >> the C++ code ? >> If the answer is "yes", how ? >> >> Thank you in advance, >> Michele >> >> -- >> Michele De Stefano >> http://www.linkedin.com/in/micdestefano >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > -- > Sebastian Walter > > Institut fuer Mathematik, Humboldt-Universitaet ? ?Tel: +49 (30) 2093-5869 > Rudower Chaussee 25, Adlershof, Berlin ? ? ? ? ? ? Fax: +49 (30) 2093-5859 > Post: Unter den Linden 6, D-10099 Berlin ? ? ? ? Email: > walter at mathematik.hu-berlin.de > WWW: http://www.mathematik.hu-berlin.de/~walter > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Michele De Stefano http://www.linkedin.com/in/micdestefano http://xoomer.virgilio.it/michele_de_stefano From amundson at fnal.gov Fri Oct 30 22:47:45 2009 From: amundson at fnal.gov (James Amundson) Date: Fri, 30 Oct 2009 16:47:45 -0500 Subject: [C++-sig] How do I wrap a static member function? Message-ID: <4AEB5F01.2070503@fnal.gov> Hi, I have the following code: ------------------------------------------------------------------------------- #include #include class Foo { public: Foo() {} ; static void doit(const char * message) { std::cout << "doing it statically: " << message << "\n"; }; void nonstatic_doit(const char *message) { std::cout << "doing it nonstatically: " << message << "\n"; }; }; using namespace boost::python; BOOST_PYTHON_MODULE(foo) { class_("Foo",init<>()) .def("doit", &Foo::doit) .def("nonstatic_doit", &Foo::nonstatic_doit) ; } ------------------------------------------------------------------------------- When I try out my foo module, I see this: In [1]: from foo import Foo In [2]: f = Foo() In [3]: f.nonstatic_doit("hello") doing it nonstatically: hello In [4]: f.doit("hello") --------------------------------------------------------------------------- ArgumentError Traceback (most recent call last) /home/amundson/work/synergia2-devel_1_0/build/synergia2/components/foundation/ in () ArgumentError: Python argument types in Foo.doit(Foo, str) did not match C++ signature: doit(char const*) ------------------------------------------------------------------------------- How can I wrap doit? Thanks, Jim Amundson From lists_ravi at lavabit.com Sat Oct 31 04:43:31 2009 From: lists_ravi at lavabit.com (Ravi) Date: Fri, 30 Oct 2009 23:43:31 -0400 Subject: [C++-sig] How do I wrap a static member function? In-Reply-To: <4AEB5F01.2070503@fnal.gov> References: <4AEB5F01.2070503@fnal.gov> Message-ID: <200910302343.31622.lists_ravi@lavabit.com> Use class_.staticmethod(...) as shown below: On Friday 30 October 2009 17:47:45 James Amundson wrote: > BOOST_PYTHON_MODULE(foo) > { > class_("Foo",init<>()) > .def("doit", &Foo::doit) .staticmethod( "doit" ) > .def("nonstatic_doit", &Foo::nonstatic_doit) > ; > } Regards, Ravi From lists_ravi at lavabit.com Sat Oct 31 04:53:27 2009 From: lists_ravi at lavabit.com (Ravi) Date: Fri, 30 Oct 2009 23:53:27 -0400 Subject: [C++-sig] Python converters for raw pointers: request for help In-Reply-To: References: Message-ID: <200910302353.28002.lists_ravi@lavabit.com> On Friday 23 October 2009 04:38:30 Michele De Stefano wrote: > typedef struct _p_Mat* Mat; Creating a converter to/from a raw pointer is rather tricky (due to the way argument type deduction handles pointers & references seamlessly, IIUC). You should either expose _p_Mat or wrap the raw pointer in a struct and then expose converters to it: struct Mat { struct _p_Mat *ptr; }; If you come up with a better way, I'd be interested. Regards, Ravi From lists_ravi at lavabit.com Sat Oct 31 05:02:37 2009 From: lists_ravi at lavabit.com (Ravi) Date: Sat, 31 Oct 2009 00:02:37 -0400 Subject: [C++-sig] [python] python + phoenix In-Reply-To: <4AD6820E.9040302@resophonic.com> References: <200910101158.46996.lists_ravi@lavabit.com> <200910122104.46505.lists_ravi@lavabit.com> <4AD6820E.9040302@resophonic.com> Message-ID: <200910310002.37065.lists_ravi@lavabit.com> On Wednesday 14 October 2009 21:59:42 troy d. straszheim wrote: > boost::function still works, and doesn't require as<>: > > boost::function myplus = std::plus(); > def("myplus", myplus); > > and old-school function objects: > > def("otherplus", std::plus()) > > I was surprised to find that it all plays nice with boost::phoenix: > > def("plus", as(arg1 + arg2)); > > def("throw_if_gt_5", > as(if_(arg1 > 5) > [ throw_(std::runtime_error("too big!!")) ] > .else_ > [ std::cout << val("okay") ])); > > And boost::phoenix plays nice with shared_ptr, which plays nice with > boost::python: > > struct X { int x; }; typedef boost::shared_ptr XPtr; > > class_("X") > .def_readwrite("x", &X::x) > .def("add7", as (arg1->*&X::x += 7)) > .def("add8", as(arg1->*&X::x += 8)) > .def("add9", as (bind(&X::x, arg1) += 9)) > ; > > the other little thing is overload resolution, for which I propose a > little helper function "unload" (underload? deload? resolve? I dunno): > > void foo(int); > void foo(double); > > def("foo", unload(foo)); > > Which is safer than > > def("foo", (void(*)(int)) foo); > > and just as safe as, and less verbose than > > void(*fooint)(int) = foo; > def("foo", fooint); > > So that's where I'm at... what do you make of that interface? This is very cool and pretty intuitive. My main concern is that one needs to build up the function type in generic code (as opposed to mpl vectors), but we do have function_types to help us. You are going to have to propose this as several small patched, before Ralf & Dave agree to it. Regards, Ravi From troy at resophonic.com Sat Oct 31 06:24:16 2009 From: troy at resophonic.com (troy d. straszheim) Date: Sat, 31 Oct 2009 01:24:16 -0400 Subject: [C++-sig] [python] python + phoenix In-Reply-To: <200910310002.37065.lists_ravi@lavabit.com> References: <200910101158.46996.lists_ravi@lavabit.com> <200910122104.46505.lists_ravi@lavabit.com> <4AD6820E.9040302@resophonic.com> <200910310002.37065.lists_ravi@lavabit.com> Message-ID: <4AEBCA00.5010902@resophonic.com> Ravi wrote: > On Wednesday 14 October 2009 21:59:42 troy d. straszheim wrote: >> >> def("plus", as(arg1 + arg2)); >> > > This is very cool and pretty intuitive. My main concern is that one needs to > build up the function type in generic code (as opposed to mpl vectors), but we > do have function_types to help us. I take it that you have a use-case where it is difficult to specify as(thing) and easy to specify as >(thing) Could you elaborate? I'm quite sure there is a way to provide (roughly) both interfaces: def("foo", as(functor())); def("foo", as >(functor())); but I'm not sure I understand the problem. > You are going to have to propose this as several small patched, > before Ralf & Dave agree to it. Shit. I knew this would happen, I've written too much code again. Dave? Ralf? -t