From itcecsa at gmail.com Mon Dec 3 07:38:31 2007 From: itcecsa at gmail.com (Guofu Chen) Date: Mon, 3 Dec 2007 01:38:31 -0500 Subject: [C++-sig] Can you tell me how to launch Matlab and run M-files from Python? Message-ID: Hi, I am now implementing a small Python project, what I am going to do is to lunch Matlab and run some M-files, and get some output from Matlab command prompt. This project will be used on both Windows 32 and Linux. I have no idea how to open Matlab from Python! Do I have to make Matlab C/C++ source codes to be Python modules so that they can be called by Python? Any suggestions would be appreciated! -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyril.bazin at info.unicaen.fr Mon Dec 3 10:07:12 2007 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Mon, 3 Dec 2007 10:07:12 +0100 Subject: [C++-sig] Can you tell me how to launch Matlab and run M-files from Python? In-Reply-To: References: Message-ID: If you want to matlab in python like if it was runned from the command line, use the python module "subprocess". This module requieres at least the version 2.4 of python. http://docs.python.org/lib/module-subprocess.html Cyril On Dec 3, 2007 7:38 AM, Guofu Chen wrote: > Hi, > > I am now implementing a small Python project, what I am going to do is to > lunch Matlab and run some M-files, and get some output from Matlab command > prompt. This project will be used on both Windows 32 and Linux. > > I have no idea how to open Matlab from Python! Do I have to make Matlab > C/C++ source codes to be Python modules so that they can be called by > Python? > > Any suggestions would be appreciated! > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cyril.bazin at info.unicaen.fr Mon Dec 3 10:07:12 2007 From: cyril.bazin at info.unicaen.fr (Cyril Bazin) Date: Mon, 3 Dec 2007 10:07:12 +0100 Subject: [C++-sig] Can you tell me how to launch Matlab and run M-files from Python? In-Reply-To: References: Message-ID: If you want to matlab in python like if it was runned from the command line, use the python module "subprocess". This module requieres at least the version 2.4 of python. http://docs.python.org/lib/module-subprocess.html Cyril On Dec 3, 2007 7:38 AM, Guofu Chen wrote: > Hi, > > I am now implementing a small Python project, what I am going to do is to > lunch Matlab and run some M-files, and get some output from Matlab command > prompt. This project will be used on both Windows 32 and Linux. > > I have no idea how to open Matlab from Python! Do I have to make Matlab > C/C++ source codes to be Python modules so that they can be called by > Python? > > Any suggestions would be appreciated! > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nickm at sitius.com Mon Dec 3 20:01:42 2007 From: nickm at sitius.com (Nikolay Mladenov) Date: Mon, 03 Dec 2007 14:01:42 -0500 Subject: [C++-sig] Wrapping an enum like class that is not an enum References: <3dc9bcf00711301325g334a9c44n7c1bfbd7a0dd14a7@mail.gmail.com> Message-ID: <47545296.23931466@sitius.com> May be you should post some more code ... Did you try class_<...>(...) . def_readonly(...) ; ? (or may be add_property ) HTH, Nikolay Mladenov Matthew Scouten wrote: > > I (a BP newbie) could use some advice on how th wrap something odd. > > The library I am using has something called an AEnum. It is a type of > enum like class. It is guaranteed to behave exactly like an enum, > except that it has some extra properties. There is an int, a string > and a symbol associated with each value. > > In spite of that, the sizeof(AEnum_blah) == sizeof(int) , Guaranteed > an AEnum is castable to and from an int > and the bits of the AEnum are identical to the bits of the int it > casts to. > > I can't wrap it as a class because it is generated by crazy macros and > meta-template programming (And besides, I don't understand it...) > > So, I thought, If this thing is Guaranteed to be just like an enum in > everyway that matters, why not pretend that it IS an enum and wrap it > like one? So I used the "enum_<>()" > > Well that works just great when passing to or returning from > functions. Except, if it is the member of a class... > > >>> from MantiCore import * > >>> o = Order() > >>> o.order_status > Traceback (most recent call last): > File "", line 1, in > TypeError: cannot create weak reference to > 'MantiCore.AEnum_OrderStatusCodes' object > > I can get around this by exporting it as a property of the class > rather than a data member, but there are a lot of them. > So, Anyone have a better way to do this? > > --------------------------------------------------------------- > _______________________________________________ > C++-sig mailing list > C++-sig at python.org > http://mail.python.org/mailman/listinfo/c++-sig From Jason.Kankiewicz at dreamworks.com Tue Dec 4 18:40:58 2007 From: Jason.Kankiewicz at dreamworks.com (Jason Kankiewicz) Date: Tue, 04 Dec 2007 09:40:58 -0800 Subject: [C++-sig] To Spicy For Py++ [was: A wrapped class contains another wrapped class. Hilarity ensues.] In-Reply-To: <997199507FD49A4EA997EE1E7626474638E4BDA862@Pan.domain-01> References: <3dc9bcf00711271159x5b839bbfib41dcb5affc7c1f0@mail.gmail.com> <7465b6170711271206h1d939e5fmf257491300865654@mail.gmail.com> <3dc9bcf00711271427q6c82ca2x51b9996916ab50b0@mail.gmail.com> <997199507FD49A4EA997EE1E7626474638E48E456B@Pan.domain-01> <474DA7C4.6040807@dreamworks.com> <997199507FD49A4EA997EE1E7626474638E4BDA862@Pan.domain-01> Message-ID: <4755912A.7040008@dreamworks.com> Scott, The CVS-repository version of GCC_XML includes compatibility headers that will work with VS2005 upon which VS2005 SP1 has been installed. Originally I had modified the included compatibility headers to compensate for the changes made by VS2005 SP1 but on a subsequent update of my working copy of the GCC_XML sources I found that equivalent changes had been made by its authors. I was developing on Windows Server 2003 so I cannot speak to whether or not GCC_XML will function with an installation of VS2005 on Vista. Regards, Jason Scott VanSickle wrote: > Jason, > > Yes, I installed SP1 a while back. It definitely helped with a few annoying VC2005 problems. There is a different SP that you have to install for Vista, in case you're developing with VS2005 on any Vista machines. We have do test on Vista, so we have all set up secondary dev machines that run Vista so we can debug on that OS. It's telling that the SP for VS2005 that would allow it to run on Vista came out a while after Vista; that probably means to me that Microsoft never did any debugging of any of their Vista "non-OS" code on Vista! > > Where exactly did you get the new headers? Are you saying that you have headers with which you can generate Python wrapper classes now? I got nowhere with the headers that I currently have from GCC_XML or VS2005. I would be very interested in being able to use Py++ to generate my headers; I am currently doing it all by hand. > > Scott V From gjcarneiro at gmail.com Tue Dec 4 19:05:10 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Tue, 4 Dec 2007 18:05:10 +0000 Subject: [C++-sig] ANNOUNCE: PyBindGen 0.8 Message-ID: The other day I released PyBindGen 0.8. Main news is that it features a new experimental header file scanner based on pygccxml (i.e., it's similar to py++ in scope, if not in maturity, but does not use boost.pythonunderneath). == What == PyBindGen is a Python module that is geared to generating C/C++ code that binds a C/C++ library for Python. It does so without extensive use of either C++ templates or C pre-processor macros. It has modular handling of C/C++ types, and can be easily extended with Python plugins. The generated code is almost as clean as what a human programmer would write, and does not depend on any library or header files besides Python itself. == Where == https://launchpad.net/pybindgen/ == NEWS == - Support C++ instance attributes through getter/setter methods - Support functions as methods of C++ classes - Support the PyObject* type - Support unsigned int, C strings (char*) (from Mark Lee) - Add basic support for enum types - New experimental automatic module generator based on C/C++ header file scanner and annotations in comments, using pygccxml - Some bug fixes -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From t_spens at yahoo.com Tue Dec 4 23:53:13 2007 From: t_spens at yahoo.com (Tim Spens) Date: Tue, 4 Dec 2007 14:53:13 -0800 (PST) Subject: [C++-sig] issues wrapping a template class Message-ID: <966028.7845.qm@web45115.mail.sp1.yahoo.com> I've never wrapped a template class before and I'm running into issues. I followed the examples at http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class Here's the template class I'm trying to wrap using boost python: namespace C4 { namespace ZEE { template class u255_buff { PUBLIC: void write(const T * contents, size_t length) { if (length_ > sizeof(contents_)) return; length_ = length; ::memcpy(contents_, contents, length); } PROTECTED: T contents_[UCHAR_MAX]; size_t length_; }; } } BOOST_PYTHON_MODULE(libzeepy) { implicitly_convertible >(); implicitly_convertible >(); class_ >("u255_buff", init >()) .def(init()) .def(init()) .def("write", &u255_buff::write) ; } >>> import ctypes >>> import libzeepy >>> import libzclientpy >>> dir(libzeepy) ['__doc__', '__file__', '__name__', 'euid', 'panid', 'u255_buff', 'zap'] >>> >>> dir(libzeepy.u255_buff) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__instance_size__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'length', 'write'] >>> >>> sig = libzclientpy.make_ssm() >>> message = 'foo bar' >>> cmessage = ctypes.c_char_p >>> cmessage.value = 'foo bar' >>> >>> sig.buffer_.write(message, len(message)) Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in u255_buff_.write(u255_buff_, str, int) did not match C++ signature: write(C4::ZEE::u255_buff {lvalue}, unsigned char const*, unsigned int) >>> >>> sig.buffer_.write(cmessage, len(message)) Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in u255_buff_.write(u255_buff_, _ctypes.SimpleType, int) did not match C++ signature: write(C4::ZEE::u255_buff {lvalue}, unsigned char const*, unsigned int) >>> I'm not really sure which parameter(s) are incorrect when calling the write function? Thanks for looking, Tim ____________________________________________________________________________________ Get easy, one-click access to your favorites. Make Yahoo! your homepage. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Wed Dec 5 07:34:36 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 5 Dec 2007 08:34:36 +0200 Subject: [C++-sig] issues wrapping a template class In-Reply-To: <966028.7845.qm@web45115.mail.sp1.yahoo.com> References: <966028.7845.qm@web45115.mail.sp1.yahoo.com> Message-ID: <7465b6170712042234x56671305m96996d22eeb709e6@mail.gmail.com> On Dec 5, 2007 12:53 AM, Tim Spens wrote: > > > I've never wrapped a template class before and I'm running into issues. > I followed the examples at http://language-binding.net/pyplusplus/documentation/how_to.html#how-to-automatically-export-template-functions-class > > Here's the template class I'm trying to wrap using boost python: > namespace C4 > { > namespace ZEE > { > template > class u255_buff > { > PUBLIC: > void write(const T * contents, size_t length) > { > if (length_ > sizeof(contents_)) > return; > > length_ = length; > ::memcpy(contents_, contents, length); > } > > PROTECTED: > T contents_[UCHAR_MAX]; > size_t length_; > > }; > } > } > > BOOST_PYTHON_MODULE(libzeepy) > { > implicitly_convertible >(); > implicitly_convertible >(); > > class_ >("u255_buff", init >()) > .def(init()) > .def(init()) > .def("write", &u255_buff::write) > ; > } > > >>> ... > I'm not really sure which parameter(s) are incorrect when calling the write function? > It has nothing to do with template classes. Next link contains explanation & solution to your problem http://language-binding.net/pyplusplus/documentation/functions/transformation/built_in/input_c_buffer.html http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/convenience.py?revision=1032&view=markup - contains source code for __convenience.pypp.hpp file -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From grant.tang at gmail.com Thu Dec 6 05:52:09 2007 From: grant.tang at gmail.com (Grant Tang) Date: Wed, 5 Dec 2007 22:52:09 -0600 Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 Message-ID: My application uses boost.pyhton to wrap c++ core to Python. It works fine on Linux, WinXP and Mac OSX. On the recently released Fedora 8, it functions correctly but always causes segmentation fault when exit Python: >>>import MyAPP >>>exit() Segmentaion fault put the exit() function in try/catch shows it's a SystemExit exception raised in exit() function. If I run Python in GDB, it gives this info at exit(): Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 46912496267664 (LWP 158127)] 0x00002aaab20885cd in rename () from /lib64/libselinux.so.1 I doubt it's releated to SELinux on Fedora. But the problem exists even if I turn off SELinux. Can anybody tell me what's the problem here and why it only happens in Fedora 8? -- Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From grant.tang at gmail.com Thu Dec 6 05:44:27 2007 From: grant.tang at gmail.com (Grant) Date: Wed, 5 Dec 2007 22:44:27 -0600 Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 Message-ID: My application use boost.pyhton to wrap c++ core to Python. It works fine on Linux, WinXP and Mac OSX. On the recently released Fedora 8, it functions correctly but always causes segmentation fault when exit Python: >>>import MyAPP >>>exit() Segmentaion fault put the exit() function in try/catch shows it's a SystemExit exception raised in exit() function. If I run Python in GDB, it gives this info at exit(): Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 46912496267664 (LWP 158127)] 0x00002aaab20885cd in rename () from /lib64/libselinux.so.1 I doubt it's releated to SELinux on Fedora. But the problem exists even if I turn off SELinux. Can anybody what's the problem here and why it only happens in Fedora 8? From rwgk at yahoo.com Thu Dec 6 17:01:31 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 6 Dec 2007 08:01:31 -0800 (PST) Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 Message-ID: <87524.14387.qm@web31112.mail.mud.yahoo.com> My guess is there is a general memory access violation, but you're getting lucky on the other platforms. I'd run valgrind to find out what's going on. valgrind should come with Fedora 8. If not, installing from sources is quick and easy. You need Python-specific suppressions for valgrind. The suppression file comes with the Python sources. I think it is called valgrind-python.supp, probably in the Misc subdirectory. If you compile your extension with -g valgrind will give you source code line numbers. Ralf ----- Original Message ---- From: Grant Tang To: c++-sig at python.org Sent: Wednesday, December 5, 2007 8:52:09 PM Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 My application uses boost.pyhton to wrap c++ core to Python. It works fine on Linux, WinXP and Mac OSX. On the recently released Fedora 8, it functions correctly but always causes segmentation fault when exit Python: >>>import MyAPP >>>exit() Segmentaion fault put the exit() function in try/catch shows it's a SystemExit exception raised in exit() function. If I run Python in GDB, it gives this info at exit(): Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 46912496267664 (LWP 158127)] 0x00002aaab20885cd in rename () from /lib64/libselinux.so.1 I doubt it's releated to SELinux on Fedora. But the problem exists even if I turn off SELinux. Can anybody tell me what's the problem here and why it only happens in Fedora 8? -- Grant -------------- next part -------------- An HTML attachment was scrubbed... URL: From adrien.saladin at gmail.com Thu Dec 6 18:12:58 2007 From: adrien.saladin at gmail.com (Adrien Saladin) Date: Thu, 6 Dec 2007 18:12:58 +0100 Subject: [C++-sig] py++ and SCons Message-ID: Hi, I'm working on a C++ library exposed to python with the help of boost-python and Py++. The project is build with SCons, but the integration of Py++ in my SConstruct file is very poor. Does someone has some experience with SCons and Py++ and want to share it ? Thanks, Adrien From jenny.duan at tradingtechnologies.com Thu Dec 6 18:12:29 2007 From: jenny.duan at tradingtechnologies.com (Jenny Duan (TT)) Date: Thu, 6 Dec 2007 11:12:29 -0600 Subject: [C++-sig] [Py++] problems running Py++ : Where to specify the compiler version In-Reply-To: <8F544985CD5FE24897B348C988320602051C32B4@chiex01> References: <8F544985CD5FE24897B348C988320602051273ED@chiex01> <47546FE1.3000008@kitware.com> <8F544985CD5FE24897B348C9883206020512747A@chiex01> <47547C2C.5010908@kitware.com> <8F544985CD5FE24897B348C988320602051274C3@chiex01> <475489F7.1070506@kitware.com> <8F544985CD5FE24897B348C98832060205127549@chiex01> <47548E77.3040506@kitware.com> <8F544985CD5FE24897B348C98832060205127724@chiex01> <47557DE3.1020508@kitware.com> <8F544985CD5FE24897B348C98832060205127764@chiex01> <475583F4.7050500@kitware.com> <8F544985CD5FE24897B348C988320602051C2E5F@chiex01> <4755B58E.8090205@kitware.com> <8F544985CD5FE24897B348C988320602051C2FA0@chiex01> <4755C549.1070103@kitware.com> <8F544985CD5FE24897B348C988320602051C2FE3@chiex01> <4755D255.103@kitware.com> <8F544985CD5FE24897B348C988320602051C3025@chiex01> <4755DCE1.8090800@kitware.com> <8F544985CD5FE24897B348C988320602051C3230@chiex01> <8F544985CD5FE24897B348C988320602051C32B4@chiex01> Message-ID: <8F544985CD5FE24897B348C988320602051C3802@chiex01> I was running Py++ gui with a simple header file, and got an error that says I didn't specify the compiler version, but I did specify it at the command line for gccxml.exe under GCC_XML location on the left side of the gui window. I guess I specified it at the wrong place. Could somebody please tell me where I am supposed to specify it? Thanks for your help, Jenny -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 25791 bytes Desc: image002.png URL: From jenny.duan at tradingtechnologies.com Thu Dec 6 18:29:41 2007 From: jenny.duan at tradingtechnologies.com (Jenny Duan (TT)) Date: Thu, 6 Dec 2007 11:29:41 -0600 Subject: [C++-sig] [Py++] problems running Py++ : Where to specify the compiler version In-Reply-To: <8F544985CD5FE24897B348C988320602051C3802@chiex01> References: <8F544985CD5FE24897B348C988320602051273ED@chiex01> <47546FE1.3000008@kitware.com> <8F544985CD5FE24897B348C9883206020512747A@chiex01> <47547C2C.5010908@kitware.com> <8F544985CD5FE24897B348C988320602051274C3@chiex01> <475489F7.1070506@kitware.com> <8F544985CD5FE24897B348C98832060205127549@chiex01> <47548E77.3040506@kitware.com> <8F544985CD5FE24897B348C98832060205127724@chiex01> <47557DE3.1020508@kitware.com> <8F544985CD5FE24897B348C98832060205127764@chiex01> <475583F4.7050500@kitware.com> <8F544985CD5FE24897B348C988320602051C2E5F@chiex01> <4755B58E.8090205@kitware.com> <8F544985CD5FE24897B348C988320602051C2FA0@chiex01> <4755C549.1070103@kitware.com> <8F544985CD5FE24897B348C988320602051C2FE3@chiex01> <4755D255.103@kitware.com> <8F544985CD5FE24897B348C988320602051C3025@chiex01> <4755DCE1.8090800@kitware.com> <8F544985CD5FE24897B348C988320602051C3230@chiex01> <8F544985CD5FE24897B348C988320602051C32B4@chiex01> <8F544985CD5FE24897B348C988320602051C3802@chiex01> Message-ID: <8F544985CD5FE24897B348C988320602051C3825@chiex01> I found the location of the gccxml_config file. Thanks. From: Jenny Duan (TT) Sent: Thursday, December 06, 2007 11:12 AM To: c++-sig at python.org Cc: Jenny Duan (TT) Subject: [Py++] problems running Py++ : Where to specify the compiler version I was running Py++ gui with a simple header file, and got an error that says I didn't specify the compiler version, but I did specify it at the command line for gccxml.exe under GCC_XML location on the left side of the gui window. I guess I specified it at the wrong place. Could somebody please tell me where I am supposed to specify it? Thanks for your help, Jenny -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/png Size: 25791 bytes Desc: image001.png URL: From gtang at bcm.tmc.edu Thu Dec 6 18:56:24 2007 From: gtang at bcm.tmc.edu (Tang, Guang) Date: Thu, 6 Dec 2007 11:56:24 -0600 Subject: [C++-sig] boost.python program crash Python interpreter at exiton Fedora 8 Message-ID: <41F968EBC39129469A28E53880F2DFCA01992C5F@BCMEVS6.ad.bcm.edu> Thanks for your reply. My application wraps a bunch of c++ classes to Python, the building process is managed by CMake. To simplify the problem. I replace one of the wrapped class to Hello class in the tutorial of boost.python. But I still get this segfault at exit. Grant "Ralf W. Grosse-Kunstleve" wrote in message news:<87524.14387.qm at web31112.mail.mud.yahoo.com>... > My guess is there is a general memory access violation, but you're getting > lucky on the other platforms. I'd run valgrind to find out what's going > on. valgrind should come with Fedora 8. If not, installing from sources > is quick and easy. > You need Python-specific suppressions for valgrind. The suppression > file comes with the Python sources. I think it is called valgrind-python.supp, > probably in the Misc subdirectory. > If you compile your extension with -g valgrind will give you source > code line numbers. > Ralf > > ----- Original Message ---- > From: Grant Tang > To: c++-sig at python.org > Sent: Wednesday, December 5, 2007 8:52:09 PM > Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 > > > My application uses boost.pyhton to wrap c++ core to Python. It works fine on > Linux, WinXP and Mac OSX. On the recently released Fedora 8, it functions > correctly but always causes segmentation fault when exit Python: > > >>>import MyAPP > >>>exit() > Segmentaion fault > > put the exit() function in try/catch shows it's a SystemExit exception > raised in exit() function. > > If I run Python in GDB, it gives this info at exit(): > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 46912496267664 (LWP 158127)] > 0x00002aaab20885cd in rename () from /lib64/libselinux.so.1 > > I doubt it's releated to SELinux on Fedora. But the problem exists even if I > > turn off SELinux. > > Can anybody tell me what's the problem here and why it only happens in Fedora 8? > > > -- > Grant > > > > From rwgk at yahoo.com Thu Dec 6 21:55:53 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Thu, 6 Dec 2007 12:55:53 -0800 (PST) Subject: [C++-sig] boost.python program crash Python interpreter at exiton Fedora 8 Message-ID: <590999.29521.qm@web31112.mail.mud.yahoo.com> I know for sure Boost.Python works under Fedora 8. Most likely the problem is in the way you build the extension. It could be any number of things, e.g. mix of .o files compiled with different compilers, or linking against the wrong libboost_python.so, etc. If you want to convince yourself: wget http://cci.lbl.gov/boostbx_bundles/2007_12_05_0104/boostbx_bundle.selfx perl boostbx_bundle.selfx This is with the boost svn from two days ago. It compiles libboost_python.so from scratch and runs a unit test at the end. Maybe the compilation/link commands shown in the build output will give you a clue how to adjust your build system. Ralf ----- Original Message ---- From: "Tang, Guang" To: c++-sig at python.org Sent: Thursday, December 6, 2007 9:56:24 AM Subject: Re: [C++-sig] boost.python program crash Python interpreter at exiton Fedora 8 Thanks for your reply. My application wraps a bunch of c++ classes to Python, the building process is managed by CMake. To simplify the problem. I replace one of the wrapped class to Hello class in the tutorial of boost.python. But I still get this segfault at exit. Grant "Ralf W. Grosse-Kunstleve" wrote in message news:<87524.14387.qm at web31112.mail.mud.yahoo.com>... > My guess is there is a general memory access violation, but you're getting > lucky on the other platforms. I'd run valgrind to find out what's going > on. valgrind should come with Fedora 8. If not, installing from sources > is quick and easy. > You need Python-specific suppressions for valgrind. The suppression > file comes with the Python sources. I think it is called valgrind-python.supp, > probably in the Misc subdirectory. > If you compile your extension with -g valgrind will give you source > code line numbers. > Ralf > > ----- Original Message ---- > From: Grant Tang > To: c++-sig at python.org > Sent: Wednesday, December 5, 2007 8:52:09 PM > Subject: [C++-sig] boost.python program crash Python interpreter at exit on Fedora 8 > > > My application uses boost.pyhton to wrap c++ core to Python. It works fine on > Linux, WinXP and Mac OSX. On the recently released Fedora 8, it functions > correctly but always causes segmentation fault when exit Python: > > >>>import MyAPP > >>>exit() > Segmentaion fault > > put the exit() function in try/catch shows it's a SystemExit exception > raised in exit() function. > > If I run Python in GDB, it gives this info at exit(): > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 46912496267664 (LWP 158127)] > 0x00002aaab20885cd in rename () from /lib64/libselinux.so.1 > > I doubt it's releated to SELinux on Fedora. But the problem exists even if I > > turn off SELinux. > > Can anybody tell me what's the problem here and why it only happens in Fedora 8? > > > -- > Grant > > > > _______________________________________________ C++-sig mailing list C++-sig at python.org http://mail.python.org/mailman/listinfo/c++-sig From roman.yakovenko at gmail.com Thu Dec 6 22:20:58 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Thu, 6 Dec 2007 23:20:58 +0200 Subject: [C++-sig] py++ and SCons In-Reply-To: References: Message-ID: <7465b6170712061320m1c3e69c9ucca8590d73473607@mail.gmail.com> On Dec 6, 2007 7:12 PM, Adrien Saladin wrote: > Hi, > > I'm working on a C++ library exposed to python with the help of > boost-python and Py++. > The project is build with SCons, but the integration of Py++ in my > SConstruct file is very poor. > > Does someone has some experience with SCons and Py++ and want to share it? Take a look on this post: http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=5612&highlight=scons Search for 'envl.Pypp' text. I tried to contact the person, but didn't succeeded. May be you will have more succes :-) You also can take a look on Py++ unittests. It generates scons files on the fly: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/fundamental_tester_base.py?view=markup P.S. If you will find solution please share it. Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Brian.Mingus at colorado.edu Fri Dec 7 06:30:42 2007 From: Brian.Mingus at colorado.edu (Brian) Date: Thu, 6 Dec 2007 22:30:42 -0700 Subject: [C++-sig] [Graph] Getting PageRank to work in BGL-Python Message-ID: <9839a05c0712062130w3ba9ad0esfd3d10763f921fb5@mail.gmail.com> I am using boost 1.34.0 and the svn head of bgl-python and having problems using page_rank, although all of the examples work for me. Do you see what's going wrong here? 1. >>> import booost.graph as bgl 2. >>> a=bgl.Graph.small_world_graph(5,5,.9, allow_self_loops=True ) 3. >>> bgl.page_rank(a,a.add_vertex_property('float') ) 4. Traceback (most recent call last): 5. File "", line 1, in 6. Boost.Python.ArgumentError: Python argument types in 7. boost.graph._graph.page_rank(Graph, GraphVertexPropertyMap) 8. did not match C++ signature: 9. page_rank(boost::graph::python::basic_graph graph, boost::vector_property_map, boost::adj_list_vertex_property_map, boost::property, boost::no_property, boost::listS>, unsigned int, unsigned int const&, boost::vertex_index_t> > > {lvalue}rank_map, boost::python::api::object done_or_iterations= 20, float damping=0.84999999999999998 ) Any input appreciated. Cheers, Brian -------------- next part -------------- An HTML attachment was scrubbed... URL: From j.reid at mail.cryst.bbk.ac.uk Fri Dec 7 10:39:59 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 07 Dec 2007 09:39:59 +0000 Subject: [C++-sig] [Graph] Getting PageRank to work in BGL-Python In-Reply-To: <9839a05c0712062130w3ba9ad0esfd3d10763f921fb5@mail.gmail.com> References: <9839a05c0712062130w3ba9ad0esfd3d10763f921fb5@mail.gmail.com> Message-ID: Brian wrote: > >>> bgl.page_rank(a,a.add_vertex_property('float') ) I think this gives you a vertex property called 'float' of type 'object'. You probably want a.add_vertex_property(name='my_name', type='float') See the add_vertex_property docstring: add_vertex_property(self, name='', type='object') -> GraphVertexPropertyMap However I still get a 'did not match C++ signature' error with this change so there must be something else as well. It does seem to work on directed graphs: dg = bgl.Digraph() bgl.page_rank(dg, dg.add_vertex_property('float')) HTH, John. From j.reid at mail.cryst.bbk.ac.uk Fri Dec 7 10:49:32 2007 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Fri, 07 Dec 2007 09:49:32 +0000 Subject: [C++-sig] [Graph] Getting PageRank to work in BGL-Python In-Reply-To: References: <9839a05c0712062130w3ba9ad0esfd3d10763f921fb5@mail.gmail.com> Message-ID: John Reid wrote: > It does seem to work on directed graphs: > dg = bgl.Digraph() > bgl.page_rank(dg, dg.add_vertex_property('float')) The page rank docs say it only works on directed graphs: Computes the PageRank of each vertex in a directed graph. For optimal results, the graph should be strongly connected. That's your problem, as a=bgl.Graph.small_world_graph(5,5,.9, allow_self_loops=True ) creates an undirected graph. From jenny.duan at tradingtechnologies.com Fri Dec 7 22:55:53 2007 From: jenny.duan at tradingtechnologies.com (Jenny Duan (TT)) Date: Fri, 7 Dec 2007 15:55:53 -0600 Subject: [C++-sig] GCCXML compile errors with boost header files and Visual Studio header files Message-ID: <8F544985CD5FE24897B348C988320602052323CE@chiex01> Gccxml does not seem to be able to handle the boost/mpl/and.hpp file. I have the most recent gccxml (retrieved the source tree and built it) and 1.34.1 boost. I was told by GCCXML support that boost/config/compiler/gcc_xml.hpp needs to exist in order for GCXXML to process boost header files and this file does exist. Please see the content of it below. Can somebody please tell me why it's not working for me? Your help would be greatly appreciated. Thanks, Jenny ----------------------------------------------------------- // Copyright Aleksey Gurtovoy 2000-2004 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/mpl for documentation. // $Source: /cvsroot/boost/boost/boost/mpl/and.hpp,v $ // $Date: 2004/09/02 15:40:41 $ // $Revision: 1.5 $ #include #if !defined(BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS) \ && !defined(BOOST_MPL_PREPROCESSING_MODE) # include # include # include # include // agurt, 19/may/04: workaround a conflict with header's // 'or' and 'and' macros, see http://tinyurl.com/3et69; 'defined(and)' // has to be checked in a separate condition, otherwise GCC complains // about 'and' being an alternative token #if defined(_MSC_VER) #if defined(and) # pragma push_macro("and") # undef and # define and(x) #endif #endif # define BOOST_MPL_PREPROCESSED_HEADER and.hpp # include #if defined(_MSC_VER) #if defined(and) # pragma pop_macro("and") #endif #endif #else # define AUX778076_OP_NAME and_ # define AUX778076_OP_VALUE1 false # define AUX778076_OP_VALUE2 true # include #endif // BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS #endif // BOOST_MPL_AND_HPP_INCLUDED ------------------------------------------------ $gccxml -fxml-start=./xml_start_symbols.txt --gccxml-gcc-options ./compiler_optons.txt world.h -fxml=world.xml --- snip--- In file included from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/helpers.h:42, from ../common/world.h:33: C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:32:13: error: operator "defined" requires an identifier C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:32:13: error: ("and" is an alternative token for "&&" in C++) C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:32:16: error: missing '(' in expression C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:43:13: error: operator "defined" requires an identifier C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:43:13: error: ("and" is an alternative token for "&&" in C++) C:/Program Files/boost/boost_1_34_1/boost/mpl/and.hpp:43:16: error: missing '(' in expression In file included from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/helpers.h:44, from ../common/world.h:33: C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:33:13: error: operator "defined" requires an identifier C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:33:13: error: ("or" is an alternative token for "||" in C++) C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:33:15: error: missing '(' in expression C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:44:13: error: operator "defined" requires an identifier C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:44:13: error: ("or" is an alternative token for "||" in C++) C:/Program Files/boost/boost_1_34_1/boost/mpl/or.hpp:44:15: error: missing '(' in expression In file included from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/compression.h:28, from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/stream_integer_wrapper.h: 32, from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/helpers.h:55, from ../common/world.h:33: G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/osabstraction/tt_crt_defs.h:3 2:2: error: #error _USE_32BIT_TIME_T must be defined for TT applications In file included from G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/coreutils/tt_systypes.h:28, from G:/corebuilds/7.0.x/misc/stream/1.3/dev/stream/streamable.h:38, from ../common/world.h:34: G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/osabstraction/tt_win_defs.h:3 1:2: error: #error you must include tt_win_defs.h as the first header file in all compilands to ensure correct settings. G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/osabstraction/tt_win_defs.h:5 5:21: error: afx.h: No such file or directory G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/osabstraction/tt_win_defs.h:5 6:24: error: afxwin.h: No such file or directory G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/osabstraction/tt_win_defs.h:5 7:23: error: afxmt.h: No such file or directory In file included from C:/Program Files/Microsoft Visual Studio 8/VC/include/fvec.h:43, from C:/Program Files/Microsoft Visual Studio 8/VC/include/dvec.h:37, from C:/Program Files/Microsoft Visual Studio 8/VC/include/intrin.h:31, from G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/coreutils/interlocked.h:29, from G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/coreutils/TTCriticalSectionBa se.h:30, from G:/corebuilds/7.0.x/misc/coreutils/1.2/dev/coreutils/ttcriticalsection.h :28, from ../common/world.h:38: C:/Program Files/Microsoft Visual Studio 8/VC/include/ivec.h:178:1: error: pasting "&" and "vec" does not give a valid preprocessing token C:/Program Files/Microsoft Visual Studio 8/VC/include/ivec.h:178:1: error: pasting "+" and "0" does not give a valid preprocessing token C:/Program Files/Microsoft Visual Studio 8/VC/include/ivec.h:179:1: error: pasting "&" and "vec" does not give a valid preprocessing token C:/Program Files/Microsoft Visual Studio 8/VC/include/ivec.h:179:1: error: pasting "+" and "1" does not give a valid preprocessing token C:/Program Files/Microsoft Visual Studio 8/VC/include/ivec.h:221:1: error: pasting "&" and "vec" does not give a valid preprocessing token --- snip--- -------------- next part -------------- An HTML attachment was scrubbed... URL: From jlisee at gmail.com Sat Dec 8 05:53:04 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Sat, 8 Dec 2007 04:53:04 +0000 (UTC) Subject: [C++-sig] py++ and SCons References: <7465b6170712061320m1c3e69c9ucca8590d73473607@mail.gmail.com> Message-ID: I am the author of the Ogre forum post, and I think that if you are going to generate buildfiles you should chose something much faster than SCons, especially since Boost.Python wrapping uses tons of headers. That is offtopic though. I have posted the GCCXML builder here: http://www.scons.org/wiki/GCCXMLBuilder I am still having reliability trouble with the full Py++ builder, its going to have wait a while before its released. -Joe From jlisee at gmail.com Sat Dec 8 05:57:19 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Sat, 8 Dec 2007 04:57:19 +0000 (UTC) Subject: [C++-sig] ANNOUNCE: PyBindGen 0.8 References: Message-ID: That is very cool to here I have one concern and a few comments. I am not sure what to think of the annotations in the comments. It feel at same time both a hack because it replaces a API around your generator and elegant because you don't have to maintain a separate set of files to represent the wrapping. The downside of this is that you would have to modify the source of any code you would wish to wrap, and that will get quite cumbersome. I am also wondering if you have decent support for standard containers? Something like Boost.Python indexing suite version 2. -Joe From jlisee at gmail.com Sat Dec 8 06:06:52 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Sat, 8 Dec 2007 05:06:52 +0000 (UTC) Subject: [C++-sig] Py++ Split Module and Implicit Conversion Message-ID: I am using split module and I wondering how to add an include file directly to the .main.cpp file and not the rest of the files output by the module builder. Its the implicit_conversion statement that likes to pull stuff into that file. Its odd because I have this in main.cpp file: bp::implicitly_convertible< std::less > const &, std::set, std::less >, std::allocator > > >(); And this in the file which wraps ram::core::Subsystem : bp::implicitly_convertible< boost::shared_ptr< ram::core::Subsystem >, boost::shared_ptr< ram::core::IUpdatable > >(); So if the implicit conversion can be made to only happen in all the other generated files, then it would remove need to include any extra headers in the main.cpp file. -Joe From gjcarneiro at gmail.com Sat Dec 8 13:19:10 2007 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Sat, 8 Dec 2007 12:19:10 +0000 Subject: [C++-sig] ANNOUNCE: PyBindGen 0.8 In-Reply-To: References: Message-ID: On 08/12/2007, Joseph Lisee wrote: > > That is very cool to here I have one concern and a few comments. I am not > sure > what to think of the annotations in the comments. It feel at same time > both a > hack because it replaces a API around your generator It does not really replace the API. Think of PyBindGen as two separate layers: 1. an low level API layer, and 2. header file scanning and annotations, which are built on top of that layer. The first layer would be needed anyway, for code modularity and readability. And the first layer can be used directly; I don't see any problem with that. and elegant because you > don't have to maintain a separate set of files to represent the > wrapping. The > downside of this is that you would have to modify the source of any code > you > would wish to wrap, and that will get quite cumbersome. It is very true. Sometimes you cannot modify the header files you're trying to wrap. On the other hand, experience tells me you can't fully automate wrapping C/C++ code without either 1) strict displine in the C/C++ code, to use certain memory management conventions (e.g. "callee should never take ownership of the objects in parameters"). or 2) the python bindings have extra information not explicit in the C language. Bottom line is, in the real world you cannot fully automate bindings; you need to give the bindings generator extra information besides the header files. Annotations is IMHO a nice way to give that extra information, when you can. Not only it's easier to follow the annotations since they're right next to the API declarations, but it gives information that even C/C++ coders will find useful. How to enter annotations when you can't modify the header files is, however, an open question. I don't have a clear answer yet, and suggestions are welcome. I am also wondering if you have decent support for standard containers? > Something like Boost.Python indexing suite version 2. Right again. PyBindGen does not have that as of yet. I would like to implement it some day. But I don't think it's as hard as it sounds, so don't lose hope just yet :) One question, though, if someone can answer. How does BP indexing suite map e.g. sequence containers? Just convert all elements to a python list? Or does it implement an object that supports iteration and sequence special methods? BTW, there are more limitations in PyBindGen that people should be aware of, such as: - Does not support multiple inheritance (I don't like MI and have no plans to implement it any time soon, unless a patch is brought to me); - Generates a single potentially big C/C++ file, no splitting done as of yet; - No support yet for one module importing definitions from another module; - Definitions nested inside class namespaces not supported (though should not be hard to implement); Thanks for the comments, -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From roman.yakovenko at gmail.com Sat Dec 8 19:11:44 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 8 Dec 2007 20:11:44 +0200 Subject: [C++-sig] Py++ Split Module and Implicit Conversion In-Reply-To: References: Message-ID: <7465b6170712081011j516a2dd2wd64ad915a181fcd7@mail.gmail.com> On Dec 8, 2007 7:06 AM, Joseph Lisee wrote: > I am using split module and I wondering how to add an include file directly to > the .main.cpp file and not the rest of the files output by the > module builder. Its the implicit_conversion statement that likes to pull stuff > into that file. > > Its odd because I have this in main.cpp file: > > bp::implicitly_convertible< std::less > > const &, std::set, > std::less >, > std::allocator > > >(); > > And this in the file which wraps ram::core::Subsystem : > > bp::implicitly_convertible< boost::shared_ptr< ram::core::Subsystem >, > boost::shared_ptr< ram::core::IUpdatable > >(); > > So if the implicit conversion can be made to only happen in all the other > generated files, then it would remove need to include any extra headers in the > main.cpp file. Next code should do the job: mb = module_builder_t( ... ) mb.add_declaration_code( '#include "you file"', tail=False ) P.S. I think I can tweak Py++ to generate better code in this case. Please open a ticket on sourceForge(http://sourceforge.net/tracker/?group_id=118209). It could be nice if you can attach the example. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Dec 8 19:22:43 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 8 Dec 2007 20:22:43 +0200 Subject: [C++-sig] py++ and SCons In-Reply-To: References: <7465b6170712061320m1c3e69c9ucca8590d73473607@mail.gmail.com> Message-ID: <7465b6170712081022m7f438f8ds4b41033516b23046@mail.gmail.com> On Dec 8, 2007 6:53 AM, Joseph Lisee wrote: > I am the author of the Ogre forum post, and I think that if you are going to > generate buildfiles you should chose something much faster than SCons, > especially since Boost.Python wrapping uses tons of headers. That is offtopic > though. I have posted the GCCXML builder here: > http://www.scons.org/wiki/GCCXMLBuilder > > I am still having reliability trouble with the full Py++ builder, its going to > have wait a while before its released. Can you puplish the code somewhere. This is not the first time Py++ users asks for such thing. I am sure some of them would be able to provide useful feedback. P.S. I will be glad to add the code to the Py++ SVN and publish it on my site. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Dec 8 19:30:17 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 8 Dec 2007 20:30:17 +0200 Subject: [C++-sig] GCCXML compile errors with boost header files and Visual Studio header files In-Reply-To: <8F544985CD5FE24897B348C988320602052323CE@chiex01> References: <8F544985CD5FE24897B348C988320602052323CE@chiex01> Message-ID: <7465b6170712081030kd8bf3far6e069ecc131470e6@mail.gmail.com> On Dec 7, 2007 11:55 PM, Jenny Duan (TT) wrote: > > > > > Gccxml does not seem to be able to handle the boost/mpl/and.hpp file. I > have the most recent gccxml (retrieved the source tree and built it) and > 1.34.1 boost. I was told by GCCXML support that > boost/config/compiler/gcc_xml.hpp needs to exist in order for GCXXML to > process boost header files and this file does exist. In order GCCXML could work on boost, the boost libraries should treat GCCXML as another compiler. Only few libraries do this. > Can somebody please tell me why it's not working for me? Your help > would be greatly appreciated. I think you should take the post to the boost-developers mailing list and ask help from MPL library authors. P.S. The latest GCCXML source code is built around GCC 4.2 compiler. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From chase.davis at chron.com Tue Dec 11 22:28:08 2007 From: chase.davis at chron.com (Chase) Date: Tue, 11 Dec 2007 15:28:08 -0600 Subject: [C++-sig] Boost.Python undefined symbol error Message-ID: Folks I apologize in advance for what I know is probably a very simple question, but I'm just an amateur programmer (with minimal C++ experience) and I'm having trouble figuring this out. I'm trying to use bjam to compile a Boost.Python-wrapped module that includes a header file from elsewhere. Everything compiles, but when I go to import the new module I've created, it throws this error: ImportError: ./hello.so: undefined symbol: _ZN8splitterC1ERKSs I've gotten the "Hello World" example to work, so Boost.Python itself seems to be working fine. I'm trying to work through this step-by-step, and it appears the issue is an included header file in my C++ code. I'm just not sure how to fix it. Here's my Jamfile: using python : 2.5 ; use-project boost : /usr/local/boost_1_34_1 ; project : requirements /boost/python//boost_python ; python-extension hello : hello.cpp ; And here's relevant bits of my C++ code (I just used the Hello World example and threw in the extra include, so I could isolate the problem. Without the splitter stuff, the code compiles fine.): #include // Added for testing purposes #include #include "splitter.h" struct World { void set(std::string msg) { this->msg = msg; string text; list lw; list ls; // Added for testing purposes splitter sp("/usr/local/share/FreeLing/en/splitter.dat"); } std::string greet() { return msg; } std::string msg; }; #include using namespace boost::python; BOOST_PYTHON_MODULE(hello) { class_("World") .def("greet", &World::greet) .def("set", &World::set) ; } This is the bjam output: Building Boost.Regex with the optional Unicode/ICU support disabled. Please refer to the Boost.Regex documentation for more information (don't panic: this is a strictly optional feature). warning: No toolsets are configured. warning: Configuring default toolset "gcc". warning: If the default is wrong, you may not be able to build C++ programs. warning: Use the "--toolset=xxxxx" option to override our guess. warning: For more configuration options, please consult warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html ...patience... ...found 1133 targets... ...updating 5 targets... MkDir1 bin MkDir1 bin/gcc-3.4.6 MkDir1 bin/gcc-3.4.6/debug gcc.compile.c++ bin/gcc-3.4.6/debug/hello.o In file included from /usr/local/boost_1_34_1/boost/python/detail/wrap_python.hpp:50, from /usr/local/boost_1_34_1/boost/python/detail/prefix.hpp:13, from /usr/local/boost_1_34_1/boost/python/args.hpp:8, from /usr/local/boost_1_34_1/boost/python.hpp:11, from hello.cpp:27: /usr/local/include/python2.5/pyconfig.h:932:1: warning: "_POSIX_C_SOURCE" redefined In file included from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/x86_64-redhat-linux/bits/os_defines.h:39, from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/x86_64-redhat-linux/bits/c++config.h:35, from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/string:45, from hello.cpp:1: /usr/include/features.h:150:1: warning: this is the location of the previous definition gcc.link.dll bin/gcc-3.4.6/debug/hello.so ...updated 5 targets... Based on some similar posts I've read, I'm guessing there's some issue with my include. Maybe something has to be linked somehow, or I need to identify something in the Jamfile? Any guidance would be appreciated. Thanks, Chase From rogeeff at gmail.com Fri Dec 14 04:22:01 2007 From: rogeeff at gmail.com (Gennadiy Rozental) Date: Thu, 13 Dec 2007 22:22:01 -0500 Subject: [C++-sig] BOOST_PYTHON_MODULE: serios usebility issue Message-ID: Hi, I believe BOOST_PYTHON_MODULE has a serios problem. At the moment I can't use library version and have to rewrite this macro locally. The problem is with usage of native C++ concatenation instead of BOOST_JOIN. For varios reasons I need to wrap the BOOST_PYTHON_MODULE macro and want to pass a name that is concatenation of several tokens. Unfortunately current implementation failes to support this. Essensially what I need is BOOST_PYTHON_MODULE( BOOST_JOIN( name, d ) ) to work properly. I can fix it myself in svn, but I prefer authors to deal with it in manner they like. Gennadiy From dahlbokum at intes.de Mon Dec 17 14:49:08 2007 From: dahlbokum at intes.de (Markus Dahlbokum) Date: Mon, 17 Dec 2007 14:49:08 +0100 Subject: [C++-sig] Static linking of python and pyqt Message-ID: <200712171449.09112.dahlbokum@intes.de> Hello, I'm trying to link python statically with qt and pyqt. I've tried this in several ways but never succeeded. At the moment the final make runs without errors but I get import errors when accessing pyqt. How can I solve this problem? Markus # installing zipimport hook import zipimport # builtin # installed zipimport hook # /opt/python-2.4.4/lib/python2.4/site.pyc matches /opt/python-2.4.4/lib/python2.4/site.py import site # precompiled from /opt/python-2.4.4/lib/python2.4/site.pyc # /opt/python-2.4.4/lib/python2.4/os.pyc matches /opt/python-2.4.4/lib/python2.4/os.py import os # precompiled from /opt/python-2.4.4/lib/python2.4/os.pyc import posix # builtin # /opt/python-2.4.4/lib/python2.4/posixpath.pyc matches /opt/python-2.4.4/lib/python2.4/posixpath.py import posixpath # precompiled from /opt/python-2.4.4/lib/python2.4/posixpath.pyc # /opt/python-2.4.4/lib/python2.4/stat.pyc matches /opt/python-2.4.4/lib/python2.4/stat.py import stat # precompiled from /opt/python-2.4.4/lib/python2.4/stat.pyc # /opt/python-2.4.4/lib/python2.4/UserDict.pyc matches /opt/python-2.4.4/lib/python2.4/UserDict.py import UserDict # precompiled from /opt/python-2.4.4/lib/python2.4/UserDict.pyc # /opt/python-2.4.4/lib/python2.4/copy_reg.pyc matches /opt/python-2.4.4/lib/python2.4/copy_reg.py import copy_reg # precompiled from /opt/python-2.4.4/lib/python2.4/copy_reg.pyc # /opt/python-2.4.4/lib/python2.4/types.pyc matches /opt/python-2.4.4/lib/python2.4/types.py import types # precompiled from /opt/python-2.4.4/lib/python2.4/types.pyc # /opt/python-2.4.4/lib/python2.4/warnings.pyc matches /opt/python-2.4.4/lib/python2.4/warnings.py import warnings # precompiled from /opt/python-2.4.4/lib/python2.4/warnings.pyc # /opt/python-2.4.4/lib/python2.4/linecache.pyc matches /opt/python-2.4.4/lib/python2.4/linecache.py import linecache # precompiled from /opt/python-2.4.4/lib/python2.4/linecache.pyc import encodings # directory /opt/python-2.4.4/lib/python2.4/encodings # /opt/python-2.4.4/lib/python2.4/encodings/__init__.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/__init__.py import encodings # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/__init__.pyc # /opt/python-2.4.4/lib/python2.4/codecs.pyc matches /opt/python-2.4.4/lib/python2.4/codecs.py import codecs # precompiled from /opt/python-2.4.4/lib/python2.4/codecs.pyc import _codecs # builtin # /opt/python-2.4.4/lib/python2.4/encodings/aliases.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/aliases.py import encodings.aliases # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/aliases.pyc # /opt/python-2.4.4/lib/python2.4/encodings/utf_8.pyc matches /opt/python-2.4.4/lib/python2.4/encodings/utf_8.py import encodings.utf_8 # precompiled from /opt/python-2.4.4/lib/python2.4/encodings/utf_8.pyc Python 2.4.4 (#1, Dec ?7 2007, 11:16:51) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import QtCore import QtCore # builtin import sip # builtin Traceback (most recent call last): ? File "", line 1, in ? SystemError: _PyImport_FixupExtension: module QtCore not loaded >>> import sys >>> print sys.builtin_module_names ('QtCore', 'QtGui', '__builtin__', '__main__', '_codecs', '_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sip', 'sys', 'thread', 'time', 'xxsubtype', 'zipimport') >>> # clear __builtin__._ # clear sys.path # clear sys.argv # clear sys.ps1 # clear sys.ps2 # clear sys.exitfunc # clear sys.exc_type # clear sys.exc_value # clear sys.exc_traceback # clear sys.last_type # clear sys.last_value # clear sys.last_traceback # clear sys.path_hooks # clear sys.path_importer_cache # clear sys.meta_path # restore sys.stdin # restore sys.stdout # restore sys.stderr # cleanup __main__ # cleanup[1] site # cleanup[1] encodings # cleanup[1] _codecs # cleanup[1] zipimport # cleanup[1] PyQt4.QtCore # cleanup[1] warnings # cleanup[1] encodings.utf_8 # cleanup[1] codecs # cleanup[1] types # cleanup[1] signal # cleanup[1] linecache # cleanup[1] posix # cleanup[1] encodings.aliases # cleanup[1] exceptions # cleanup[2] copy_reg # cleanup[2] sip # cleanup[2] posixpath # cleanup[2] os.path # cleanup[2] stat # cleanup[2] UserDict # cleanup[2] os # cleanup sys # cleanup __builtin__ # cleanup ints: 7 unfreed ints in 1 out of 3 blocks # cleanup floats From jlisee at gmail.com Tue Dec 18 10:01:29 2007 From: jlisee at gmail.com (Joseph Lisee) Date: Tue, 18 Dec 2007 09:01:29 +0000 (UTC) Subject: [C++-sig] Py++ Split Module and Implicit Conversion References: <7465b6170712081011j516a2dd2wd64ad915a181fcd7@mail.gmail.com> Message-ID: > P.S. I think I can tweak Py++ to generate better code in this case. > Please open a ticket on > sourceForge(http://sourceforge.net/tracker/?group_id=118209). It could > be nice if you can attach the example. Posted: http://sourceforge.net/tracker/index.php?func=detail&aid=1852896&group_id=118209&atid=684318 -Joe From dcarpman at ll.mit.edu Thu Dec 20 00:41:34 2007 From: dcarpman at ll.mit.edu (Carpman, David) Date: Wed, 19 Dec 2007 18:41:34 -0500 Subject: [C++-sig] Exposing C Array members to python using boost Message-ID: Hello, I've been reading the archives on the topic of how to expose read/write access of C-arrays to python using boost::python, but what I could find was several years old. Some of the examples reference files that no longer exist, particularly in the indexing/container suite area. I would very much appreciate some wisdom on this subject from this list, if folks would be so kind. :) >From what I've read, Raoul Gough's indexing suite is needed to convert the arrays to python lists. I see the vector and map examples in the boost distribution (I have tried 1.35-PR1 and svn rev 42152) but nothing having to do with arrays. http://osdir.com/ml/python.c++/2003-11/msg00185.html seems to indicate Raoul had a version of the indexing suite that supported arrays in 2003, but I can't find anything about it. Has anything changed or been done since 2003 for this? Here is my situation: I'm trying to wrap some legacy C-structures that define a network packet structure that will be written by python and read by some embedded computer. I have no control over the definition of these structures, nor can I add to or change the header files. My hang-up is that some of the members in these structures are defined as C-arrays, for example, int numsamples[32]. I would like to have access in python to the elements of these arrays for reading and writing. Scalar primitive members work fine. Example: #include #include #include //The Foo struct definition would be in another header that cannot be altered struct Foo { int a[8]; }; BOOST_PYTHON_MODULE(TestCArrays) { boost::python::class_< Foo >("Foo", boost::python::init<>() ) .def_readwrite("a", &Foo::a) ; } Gives me: (sorry for the long lines) /usr/include/boost/python/data_members.hpp: In member function 'void boost::python::detail::member::operator()(Class&, typename boost::python::detail::value_arg::type) const [with Data = int [8], Class = Foo]': /usr/include/boost/python/detail/invoke.hpp:81: instantiated from 'PyObject* boost::python::detail::invoke(boost::python::detail::invoke_tag_, const RC&, F&, AC0&, AC1&) [with RC = int, F = boost::python::detail::member, AC0 = boost::python::arg_from_python, AC1 = boost::python::arg_from_python]' /usr/include/boost/python/detail/caller.hpp:199: instantiated from 'PyObject* boost::python::detail::caller_arity<2u>::impl::operator()(PyObject*, PyObject*) [with F = boost::python::detail::member, Policies = boost::python::default_call_policies, Sig = boost::mpl::vector3]' /usr/include/boost/python/object/py_function.hpp:38: instantiated from 'PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller, boost::python::default_call_policies, boost::mpl::vector3 >]' testcarray.cpp:34: instantiated from here /usr/include/boost/python/data_members.hpp:64: error: ISO C++ forbids assignment of arrays How would I define Foo's python wrapper class_ so that I would have the following kind of access in python (perhaps using the indexing suite)? Myfoo = Foo() Myfoo.a[0] = 1 Myfoo.a[1] = 2 I would like to avoid having to write C++ wrapper classes for the C-structs containing the C-arrays, as there are many dozens of them. I'd be very thankful if someone could help! Regards, David Carpman From Bruce_Sherwood at ncsu.edu Thu Dec 20 18:19:20 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Thu, 20 Dec 2007 12:19:20 -0500 Subject: [C++-sig] Numpy or Boost problem Message-ID: <476AA418.4080108@ncsu.edu> I'm not sure whether this is a Numpy problem or a Boost problem, so I'm posting to both communities. In old Numeric, type(sqrt(5.5)) was float, but in numpy, type(sqrt(5.5)) is numpy.float64. This leads to a big performance hit in calculations in a beta version of VPython, using the VPython 3D "vector" class, compared with the old version that used Numeric (VPython is a 3D graphics module for Python; see vpython.org). Operator overloading of the VPython vector class works fine for vector*sqrt(5.5) but not for sqrt(5.5)*vector. The following free function catches 5.5*vector but fails to catch sqrt(5.5)*vector, whose type ends up as numpy.ndarray instead of the desired vector, with concomitant slow conversions in later vector calculations: inline vector operator*( const double& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } I've thrashed around on this, including trying to add this: inline vector operator*( const npy_float64& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } But the compiler correctly complains that this is in conflict with the version of double*vector, since in fact npy_float64 is actually double. It's interesting and presumably meaningful to the knowledgeable (not me) that vector*sqrt(5.5) yields a vector, even though the overloading speaks of double, not a specifically numpy name: inline vector operator*( const double s) const throw() { return vector( s*x, s*y, s*z); } VPython uses Boost, and the glue concerning vectors includes the following: py::class_("vector", py::init< py::optional >()) .def( self * double()) .def( double() * self) As far as I can understand from the Boost Python documentation, this is the proper way to specify the left-hand and right-hand overloadings. But do I have to add something like .def( npy_float64() * self)? Help would be much appreciated. Bruce Sherwood From lists at informa.tiker.net Fri Dec 21 06:23:04 2007 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Fri, 21 Dec 2007 00:23:04 -0500 Subject: [C++-sig] [patch] STL input iterator does not propagate exceptions Message-ID: <200712210023.13569.lists@informa.tiker.net> Hi all, I get a segfault if I use boost::python::stl_input_iterator from C++, and the Python code (a generator or some such) that I iterate off of raises an exception (such as KeyboardInterrupt, which makes it easy to test). This is because a NULL return from PyIter_Next is always interpreted as "end of list", and not as the error that it may well be. Attached patch fixes this. Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: bpl-stl-iterator-prop-ex-2007-12-20.patch Type: text/x-diff Size: 635 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From lists at informa.tiker.net Fri Dec 21 07:16:52 2007 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Fri, 21 Dec 2007 01:16:52 -0500 Subject: [C++-sig] Vector indexing suite::extend should take general iterables Message-ID: <200712210116.53754.lists@informa.tiker.net> Hi all, The extend() method that is generated as part of the vector_indexing_suite insists on calling __len__() on its argument, without much need. This prevents the useful construct vec.extend(generator expression) from working. :( Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From Bruce_Sherwood at ncsu.edu Fri Dec 21 17:24:19 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Fri, 21 Dec 2007 11:24:19 -0500 Subject: [C++-sig] Numpy or Boost problem Message-ID: <476BE8B3.8050503@ncsu.edu> I'm not sure whether this is a Numpy problem or a Boost problem, so I'm posting to both communities. (I'm subscribed to both lists, but an attempt to post yesterday to this Boost list seems never have gotten to the archives, so I'm trying again. My apologies if this shows up twice here.) In old Numeric, type(sqrt(5.5)) was float, but in numpy, type(sqrt(5.5)) is numpy.float64. This leads to a big performance hit in calculations in a beta version of VPython, using the VPython 3D "vector" class, compared with the old version that used Numeric (VPython is a 3D graphics module for Python; see vpython.org). Operator overloading of the VPython vector class works fine for vector*sqrt(5.5) but not for sqrt(5.5)*vector. The following free function catches 5.5*vector but fails to catch sqrt(5.5)*vector, whose type ends up as numpy.ndarray instead of the desired vector, with concomitant slow conversions in later vector calculations: inline vector operator*( const double& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } I've thrashed around on this, including trying to add this: inline vector operator*( const npy_float64& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } But the compiler correctly complains that this is in conflict with the version of double*vector, since in fact npy_float64 is actually double. It's interesting and presumably meaningful to the knowledgeable (not me) that vector*sqrt(5.5) yields a vector, even though the overloading speaks of double, not a specifically numpy name: inline vector operator*( const double s) const throw() { return vector( s*x, s*y, s*z); } VPython uses Boost, and the glue concerning vectors includes the following: py::class_("vector", py::init< py::optional >()) .def( self * double()) .def( double() * self) As far as I can understand from the Boost Python documentation, this is the proper way to specify the left-hand and right-hand overloadings. But do I have to add something like .def( npy_float64() * self)? Help would be much appreciated. Bruce Sherwood From roman.yakovenko at gmail.com Fri Dec 21 23:00:09 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 22 Dec 2007 00:00:09 +0200 Subject: [C++-sig] Exposing C Array members to python using boost In-Reply-To: References: Message-ID: <7465b6170712211400p429b0abdg232e24692b407e06@mail.gmail.com> On Dec 20, 2007 1:41 AM, Carpman, David wrote: > Hello, > > I've been reading the archives on the topic of how to expose read/write access of C-arrays to python using boost::python, but what I could find was several years old. Some of the examples reference files that no longer exist, particularly in the indexing/container suite area. I would very much appreciate some wisdom on this subject from this list, if folks would be so kind. :) > > >From what I've read, Raoul Gough's indexing suite is needed to convert the arrays to python lists. I see the vector and map examples in the boost distribution (I have tried 1.35-PR1 and svn rev 42152) but nothing having to do with arrays. http://osdir.com/ml/python.c++/2003-11/msg00185.html seems to indicate Raoul had a version of the indexing suite that supported arrays in 2003, but I can't find anything about it. Has anything changed or been done since 2003 for this? New indexing suite is not integrated with Boost.Python. You can find it here: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/indexing_suite_v2/ > Here is my situation: I'm trying to wrap some legacy C-structures that define a network packet structure that will be written by python and read by some embedded computer. I have no control over the definition of these structures, nor can I add to or change the header files. My hang-up is that some of the members in these structures are defined as C-arrays, for example, int numsamples[32]. I would like to have access in python to the elements of these arrays for reading and writing. Scalar primitive members work fine. > I would like to avoid having to write C++ wrapper classes for the C-structs containing the C-arrays, as there are many dozens of them. > I'd be very thankful if someone could help! Take a look on next code: http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusplus/code_repository/array_1.py?revision=1097&view=markup search for register_array_1 function. You can also to try Py++(http://language-binding.net/pyplusplus/pyplusplus.html), code generator for Boost.Python library, it handles such cases automatically. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From lists at informa.tiker.net Sun Dec 23 06:41:34 2007 From: lists at informa.tiker.net (Andreas =?iso-8859-1?q?Kl=F6ckner?=) Date: Sun, 23 Dec 2007 00:41:34 -0500 Subject: [C++-sig] [patch] STL input iterator does not propagate exceptions In-Reply-To: <200712210023.13569.lists@informa.tiker.net> References: <200712210023.13569.lists@informa.tiker.net> Message-ID: <200712230041.41357.lists@informa.tiker.net> On Freitag 21 Dezember 2007, Andreas Kl?ckner wrote: > Hi all, > > I get a segfault if I use boost::python::stl_input_iterator from C++, and > the Python code (a generator or some such) that I iterate off of raises an > exception (such as KeyboardInterrupt, which makes it easy to test). This is > because a NULL return from PyIter_Next is always interpreted as "end of > list", and not as the error that it may well be. > > Attached patch fixes this. > > Andreas Can somebody please just commit this? It fixes a pretty obvious bug. Thanks Andreas -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From rwgk at yahoo.com Sun Dec 23 07:43:59 2007 From: rwgk at yahoo.com (Ralf W. Grosse-Kunstleve) Date: Sat, 22 Dec 2007 22:43:59 -0800 (PST) Subject: [C++-sig] [patch] STL input iterator does not propagate exceptions Message-ID: <919095.63484.qm@web31111.mail.mud.yahoo.com> Ideas: - write Erik Niebler directly (original author; may not monitor this list) - provide a test that fails without the patch. E.g. add to the corresponding file in boost/libs/python/test. Ralf ----- Original Message ---- From: Andreas Kl?ckner To: Development of Python/C++ integration Sent: Saturday, December 22, 2007 9:41:34 PM Subject: Re: [C++-sig] [patch] STL input iterator does not propagate exceptions On Freitag 21 Dezember 2007, Andreas Kl?ckner wrote: > Hi all, > > I get a segfault if I use boost::python::stl_input_iterator from C++, and > the Python code (a generator or some such) that I iterate off of raises an > exception (such as KeyboardInterrupt, which makes it easy to test). This is > because a NULL return from PyIter_Next is always interpreted as "end of > list", and not as the error that it may well be. > > Attached patch fixes this. > > Andreas Can somebody please just commit this? It fixes a pretty obvious bug. Thanks Andreas From Bruce_Sherwood at ncsu.edu Wed Dec 26 07:11:58 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Wed, 26 Dec 2007 01:11:58 -0500 Subject: [C++-sig] Overloading sqrt(5.5)*myvector Message-ID: <4771F0AE.40406@ncsu.edu> Sorry to repeat myself and be insistent, but could someone please at least comment on whether I'm doing anything obviously wrong, even if you don't immediately have a solution to my serious problem? There was no response to my question (see copy below) which I sent to both the numpy and Boost mailing lists. To the Boost experts: Is there something wrong, or something I could/should change in how I'm trying to define to Boost the overloaded multiplication of a numpy square root (or other numpy function) times my own "vector" object? I'm seeing a huge performance hit in going from Numeric to numpy because Numeric sqrt returned float whereas numpy sqrt returns numpy.float64, so that the result is not one of my vector objects. I don't have a problem with myvector*sqrt(5.5). Here is what I currently am doing: py::class_("vector", py::init< py::optional >()) .def( self * double()) .def( double() * self) Desperately, Bruce Sherwood ------------------- I'm not sure whether this is a Numpy problem or a Boost problem, so I'm posting to both communities. (I'm subscribed to both lists, but an attempt to post yesterday to this Boost list seems never have gotten to the archives, so I'm trying again. My apologies if this shows up twice here.) In old Numeric, type(sqrt(5.5)) was float, but in numpy, type(sqrt(5.5)) is numpy.float64. This leads to a big performance hit in calculations in a beta version of VPython, using the VPython 3D "vector" class, compared with the old version that used Numeric (VPython is a 3D graphics module for Python; see vpython.org). Operator overloading of the VPython vector class works fine for vector*sqrt(5.5) but not for sqrt(5.5)*vector. The following free function catches 5.5*vector but fails to catch sqrt(5.5)*vector, whose type ends up as numpy.ndarray instead of the desired vector, with concomitant slow conversions in later vector calculations: inline vector operator*( const double& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } I've thrashed around on this, including trying to add this: inline vector operator*( const npy_float64& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } But the compiler correctly complains that this is in conflict with the version of double*vector, since in fact npy_float64 is actually double. It's interesting and presumably meaningful to the knowledgeable (not me) that vector*sqrt(5.5) yields a vector, even though the overloading speaks of double, not a specifically numpy name: inline vector operator*( const double s) const throw() { return vector( s*x, s*y, s*z); } VPython uses Boost, and the glue concerning vectors includes the following: py::class_("vector", py::init< py::optional >()) .def( self * double()) .def( double() * self) As far as I can understand from the Boost Python documentation, this is the proper way to specify the left-hand and right-hand overloadings. But do I have to add something like .def( npy_float64() * self)? Help would be much appreciated. Bruce Sherwood From roman.yakovenko at gmail.com Wed Dec 26 08:40:50 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 26 Dec 2007 09:40:50 +0200 Subject: [C++-sig] Overloading sqrt(5.5)*myvector In-Reply-To: <4771F0AE.40406@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> Message-ID: <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> On Dec 26, 2007 8:11 AM, Bruce Sherwood wrote: > Sorry to repeat myself and be insistent, but could someone please at > least comment on whether I'm doing anything obviously wrong, even if you > don't immediately have a solution to my serious problem? There was no > response to my question (see copy below) which I sent to both the numpy > and Boost mailing lists. > > To the Boost experts: Is there something wrong, or something I > could/should change in how I'm trying to define to Boost the overloaded > multiplication of a numpy square root (or other numpy function) times my > own "vector" object? I'm seeing a huge performance hit in going from > Numeric to numpy because Numeric sqrt returned float whereas numpy sqrt > returns numpy.float64, so that the result is not one of my vector > objects. I don't have a problem with myvector*sqrt(5.5). Here is what I > currently am doing: > > py::class_("vector", py::init< py::optional double> >()) > .def( self * double()) > .def( double() * self) > > Desperately, If I understand you right, than you can do something like this: replace __mul__ method of numpy.float64 class: old_mul = numpy.float64.__mul__ def new_mul( self, other ): if other isinstance( vector ): return other*self else: return old_mul( self, other ) numpy.float64.__mul__ = new_mul HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Bruce_Sherwood at ncsu.edu Thu Dec 27 05:35:16 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Wed, 26 Dec 2007 23:35:16 -0500 Subject: [C++-sig] Overloading sqrt(5.5)*myvector In-Reply-To: <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> Message-ID: <47732B84.70400@ncsu.edu> Thanks for the suggestion. It hadn't occurred to me to try to override numpy as you suggest. However, when I try the code shown below as the start of a test of this scheme, I get the following error: Traceback (most recent call last): File "C:\Documents and Settings\Bruce\My Documents\0VPythonWork\vectors.py", line 24, in numpy.float64.__mul__ = new_mul TypeError: can't set attributes of built-in/extension type 'numpy.float64' I'm copying this to the numpy discussion list, as maybe someone there will see where to go starting from your suggestion. Bruce Sherwood --------------- import numpy class vector(object): def __init__(self,x,y,z): self.data = [x,y,z] def __mul__(self,other): return vector(other*self.data[0], other*self.data[1], other*self.data[2]) __rmul__ = __mul__ def show(self): print self.data old_mul = numpy.float64.__mul__ def new_mul( self, other ): if isinstance( other, vector ): return other*self else: return old_mul( self, other ) numpy.float64.__mul__ = new_mul a = vector(1,2,3) a.show() b = 5*a b.show() c = a*7 c.show() Roman Yakovenko wrote: > On Dec 26, 2007 8:11 AM, Bruce Sherwood wrote: > >> Sorry to repeat myself and be insistent, but could someone please at >> least comment on whether I'm doing anything obviously wrong, even if you >> don't immediately have a solution to my serious problem? There was no >> response to my question (see copy below) which I sent to both the numpy >> and Boost mailing lists. >> >> To the Boost experts: Is there something wrong, or something I >> could/should change in how I'm trying to define to Boost the overloaded >> multiplication of a numpy square root (or other numpy function) times my >> own "vector" object? I'm seeing a huge performance hit in going from >> Numeric to numpy because Numeric sqrt returned float whereas numpy sqrt >> returns numpy.float64, so that the result is not one of my vector >> objects. I don't have a problem with myvector*sqrt(5.5). Here is what I >> currently am doing: >> >> py::class_("vector", py::init< py::optional> double> >()) >> .def( self * double()) >> .def( double() * self) >> >> Desperately, >> > > If I understand you right, than you can do something like this: > > replace __mul__ method of numpy.float64 class: > > old_mul = numpy.float64.__mul__ > > def new_mul( self, other ): > if other isinstance( vector ): > return other*self > else: > return old_mul( self, other ) > > numpy.float64.__mul__ = new_mul > > HTH > > From Bruce_Sherwood at ncsu.edu Thu Dec 27 16:15:07 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Thu, 27 Dec 2007 10:15:07 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4773BD97.1000703@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> Message-ID: <4773C17B.4050802@ncsu.edu> I should have added: This structure worked with the older version of VPython which used Numeric, but it doesn't work in the beta version which uses numpy. Since I don't know enough about either numpy or Boost, I'm left guessing which subsystem is the source of my difficulties, and clueless about how to remedy them. Bruce Sherwood Bruce Sherwood wrote: > Thanks for the comment, which limits the range of possible solutions. > The VPython vector class is implemented in C++, not in Python. I made up > the simple test in my previous note to try out the solution that had > been offered and which you have usefully ruled out. Here is the relevant > part of the vector class, which indeed doesn't look like an ndarray: > > inline vector > operator*( const double s) const throw() > { return vector( s*x, s*y, s*z); } > > and here is the free function for right multiplication: > > inline vector > operator*( const double& s, const vector& v) > { return vector( s*v.x, s*v.y, s*v.z); } > > Maybe the unsolvable problem is in the Boost definitions: > > py::class_("vector", py::init< py::optional double> >()) > .def( self * double()) > .def( double() * self) > > Left multiplication is fine, but right multiplication isn't. > > Bruce Sherwood > > Robert Kern wrote: > >> Bruce Sherwood wrote: >> >> >>> Thanks for the suggestion. It hadn't occurred to me to try to override >>> numpy as you suggest. However, when I try the code shown below as the >>> start of a test of this scheme, I get the following error: >>> >>> Traceback (most recent call last): >>> File "C:\Documents and Settings\Bruce\My >>> Documents\0VPythonWork\vectors.py", line 24, in >>> numpy.float64.__mul__ = new_mul >>> TypeError: can't set attributes of built-in/extension type 'numpy.float64' >>> >>> I'm copying this to the numpy discussion list, as maybe someone there >>> will see where to go starting from your suggestion. >>> >>> >> Like most (or all) builtin-types, the numpy float scalars do not permit >> replacing their methods from Python. >> >> I'm not familiar with vpython's vector. If you can make it "not look like an >> ndarray", then you should be able to just implement __rmul__ on vector. >> >> >> > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > From bioinformed at gmail.com Thu Dec 27 16:30:02 2007 From: bioinformed at gmail.com (Kevin Jacobs ) Date: Thu, 27 Dec 2007 10:30:02 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4773C17B.4050802@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> Message-ID: <2e1434c10712270730y61d694d8u7551e92b023e8cb8@mail.gmail.com> Hi Bruce, I have to add that I don't know the answer to your question either, but I do know that it is solvable and that once the list experts return, enlightenment will soon follow. My confidence comes from knowing the Python internals for how left and right multiplication are performed. As long as the "left" __mul__ operator returns NotImplemented, then the __rmul__ method will be attempted (see http://docs.python.org/ref/numeric-types.html). Of course, I don't know how to declare such a beast in Boost, having never used it, but I'm sure it is possible. My intuition is that the first problem you need to solve is getting Boot to generate the appropriate __rmul__ method. The second problem, if it even exists, is ensuring that __mul__ returns NotImplemented. Best of luck, -Kevin On Dec 27, 2007 10:15 AM, Bruce Sherwood wrote: > I should have added: This structure worked with the older version of > VPython which used Numeric, but it doesn't work in the beta version > which uses numpy. Since I don't know enough about either numpy or Boost, > I'm left guessing which subsystem is the source of my difficulties, and > clueless about how to remedy them. > > Bruce Sherwood > > Bruce Sherwood wrote: > > Thanks for the comment, which limits the range of possible solutions. > > The VPython vector class is implemented in C++, not in Python. I made up > > the simple test in my previous note to try out the solution that had > > been offered and which you have usefully ruled out. Here is the relevant > > part of the vector class, which indeed doesn't look like an ndarray: > > > > inline vector > > operator*( const double s) const throw() > > { return vector( s*x, s*y, s*z); } > > > > and here is the free function for right multiplication: > > > > inline vector > > operator*( const double& s, const vector& v) > > { return vector( s*v.x, s*v.y, s*v.z); } > > > > Maybe the unsolvable problem is in the Boost definitions: > > > > py::class_("vector", py::init< py::optional > double> >()) > > .def( self * double()) > > .def( double() * self) > > > > Left multiplication is fine, but right multiplication isn't. > > > > Bruce Sherwood > > > > Robert Kern wrote: > > > >> Bruce Sherwood wrote: > >> > >> > >>> Thanks for the suggestion. It hadn't occurred to me to try to override > >>> numpy as you suggest. However, when I try the code shown below as the > >>> start of a test of this scheme, I get the following error: > >>> > >>> Traceback (most recent call last): > >>> File "C:\Documents and Settings\Bruce\My > >>> Documents\0VPythonWork\vectors.py", line 24, in > >>> numpy.float64.__mul__ = new_mul > >>> TypeError: can't set attributes of built-in/extension type ' > numpy.float64' > >>> > >>> I'm copying this to the numpy discussion list, as maybe someone there > >>> will see where to go starting from your suggestion. > >>> > >>> > >> Like most (or all) builtin-types, the numpy float scalars do not permit > >> replacing their methods from Python. > >> > >> I'm not familiar with vpython's vector. If you can make it "not look > like an > >> ndarray", then you should be able to just implement __rmul__ on vector. > >> > >> > >> > > _______________________________________________ > > Numpy-discussion mailing list > > Numpy-discussion at scipy.org > > http://projects.scipy.org/mailman/listinfo/numpy-discussion > > > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > -------------- next part -------------- An HTML attachment was scrubbed... URL: From nindi73 at yahoo.co.uk Fri Dec 28 00:16:24 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Thu, 27 Dec 2007 23:16:24 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <424495.84366.qm@web27911.mail.ukl.yahoo.com> I am using pygccxml to parse C++ code and it all is working like a dream but for one thing. When I explicitly instantiate std::vector?double,std::allocator?double? ? pygccxml doesn't seem to pick up the default parameters in the constructors. Specifically, I am using libstdc++ from gnu, one of the constructors for std::vector has the following signature explicit vector(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) So I expect calldef_t.required_args to be size_type ( or whatever it actualy is) and expect calldef_t.optional_args to be the other 2. This, however is not the case, I see all arguments as being in calldef_t.required_args. I cannot on the other hand reproduce this behaviour for my own classes, there it works as expected. Any suggestions or enlightenment would be greatly aprieciated. __________________________________________________________ Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com From roman.yakovenko at gmail.com Fri Dec 28 09:39:24 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Fri, 28 Dec 2007 10:39:24 +0200 Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor In-Reply-To: <424495.84366.qm@web27911.mail.ukl.yahoo.com> References: <424495.84366.qm@web27911.mail.ukl.yahoo.com> Message-ID: <7465b6170712280039x1c1fdd16i217daaf9507ed333@mail.gmail.com> On Dec 28, 2007 1:16 AM, Nindi Singh wrote: > I am using pygccxml to parse C++ code and it all is working like a dream but for one thing. > > When I explicitly instantiate std::vector?double,std::allocator?double? ? > > pygccxml doesn't seem to pick up the default parameters in the constructors. > > Specifically, I am using libstdc++ from gnu, one of the constructors for std::vector has the following signature > > > > > > explicit vector(size_type __n, > > const value_type& __value = value_type(), > > const allocator_type& __a = allocator_type()) > > > > So I expect calldef_t.required_args to be size_type ( or whatever it actualy is) > > and expect calldef_t.optional_args to be the other 2. This, however is not the case, I see all > > arguments as being in calldef_t.required_args. I cannot on the other hand reproduce this > > behaviour for my own classes, there it works as expected. > > > > Any suggestions or enlightenment would be greatly aprieciated. > You didn't specified the versions (std & gccxml) you use. GCC-XML sometimes replace std headers with its own implementation. May be it replaced the vector file and doesn't specify default arguments. You can find replaced header files under GCC-XML installed directory. HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From dcarpman at ll.mit.edu Fri Dec 28 19:02:46 2007 From: dcarpman at ll.mit.edu (Carpman, David) Date: Fri, 28 Dec 2007 13:02:46 -0500 Subject: [C++-sig] Exposing C Array members to python using boost In-Reply-To: Message-ID: > -----Original Message----- > Message: 2 > Date: Sat, 22 Dec 2007 00:00:09 +0200 > From: "Roman Yakovenko" > Subject: Re: [C++-sig] Exposing C Array members to python using boost > To: "Development of Python/C++ integration" > Message-ID: > <7465b6170712211400p429b0abdg232e24692b407e06 at mail.gmail.com> > Content-Type: text/plain; charset=ISO-8859-1 > > On Dec 20, 2007 1:41 AM, Carpman, David wrote: > > Here is my situation: I'm trying to wrap some legacy C-structures that > define a network packet structure that will be written by python and read > by some embedded computer. I have no control over the definition of these > structures, nor can I add to or change the header files. My hang-up is > that some of the members in these structures are defined as C-arrays, for > example, int numsamples[32]. I would like to have access in python to the > elements of these arrays for reading and writing. Scalar primitive members > work fine. > > > I would like to avoid having to write C++ wrapper classes for the C- > structs containing the C-arrays, as there are many dozens of them. > > I'd be very thankful if someone could help! > > Take a look on next code: > > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/pyplusp > lus/code_repository/array_1.py?revision=1097&view=markup > > search for register_array_1 function. > > You can also to try > Py++(http://language-binding.net/pyplusplus/pyplusplus.html), code > generator for Boost.Python library, it handles such cases > automatically. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > Thanks very much for the reply, Roman. I tried Py++ and it indeed automatically handles the case I outlined above concerning C-array members, and with much less tedious writing of registration code. I also found it convenient to use to insert some other C++ code for each of my structures that normally I wrote by hand. The API docs and examples on your webpage were very helpful. Warm regards, David Carpman From nindi73 at yahoo.co.uk Fri Dec 28 19:35:01 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Fri, 28 Dec 2007 18:35:01 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <777533.56401.qm@web27903.mail.ukl.yahoo.com> Roman, The output from gccxml -v is : __________________________________________________ #include wrapper search starts here: /usr/share/gccxml-0.7/GCC/4.1 #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.1.3 /usr/include/c++/4.1.3/x86_64-linux-gnu /usr/include/c++/4.1.3/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.1.3/include /usr/include End of search list. __________________________________________________ The header file example.hpp is _________________________________________________ #ifndef TESTVECTOR #define TESTVECTOR #include template std::vector; #endif ________________________________________________ The pygccxml script is ________________________________________________ import sys from pygccxml import parser from pygccxml import declarations from pygccxml.declarations import templates from pygccxml.declarations import type_traits decls = parser.parse( ['example.hpp'])#, config ) global_ns = declarations.get_global_namespace( decls ) query = declarations.custom_matcher_t (lambda vec : templates.name(vec.name)=='vector') vectorClass = global_ns.classes(function=query) def processArgument(arg): if type_traits.is_const(arg): return 'const '+processArgument(type_traits.remove_const(arg)) + ' ' if type_traits.is_reference(arg): return processArgument(type_traits.remove_reference(arg)) + '&' if type_traits.is_pointer(arg): return processArgument(type_traits.remove_pointer(arg)) + '*' if type_traits.is_fundamental(arg): return str(arg) if type_traits.is_class(arg): theType = type_traits.remove_declarated(arg) return theType.demangled if type_traits.is_class_declaration(arg): theType = type_traits.remove_declarated(arg) return theType.demangled for class_ in vectorClass: theConstructors = class_.constructors() for c in theConstructors: print '\n\n' print 'name :',c.demangled print 'location :',c.location.file_name if len(c.required_args)==0: print 'No required args' else : print 'required args:' for a in c.required_args: print ' ',processArgument(a.type) if len(c.optional_args)==0: print 'No optional args' else : print 'optional args:' for a in c.optional_args: print ' ',processArgument(a.type) ______________________________________________________________________ INFO Parsing source file "example.hpp" ... INFO gccxml cmd: /usr/bin/gccxml -I"." "example.hpp" -fxml="/tmp/tmpJvYj92.xml" name : std::vector >::vector(std::allocator const&) location : /usr/include/c++/4.1.3/bits/stl_vector.h required args: const std::allocator & No optional args name : std::vector >::vector(unsigned long, double const&, std::allocator const&) location : /usr/include/c++/4.1.3/bits/stl_vector.h required args: size_t const double & const std::allocator & No optional args name : std::vector >::vector(std::vector > const&) location : /usr/include/c++/4.1.3/bits/stl_vector.h required args: const std::vector > & No optional args The output from this script is ____________________________________________________ In /usr/include/c++/4.1.3/bits/stl_vector.h line 202 : vector(const allocator_type& __a = allocator_type()) line 214-215 : vector(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) line 232 : vector(const vector& __x) I just cannot figure out why the optional parameters ( allocator ) do not show up as optional __________________________________________________________ Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com From nindi73 at yahoo.co.uk Fri Dec 28 20:52:19 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Fri, 28 Dec 2007 19:52:19 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <414459.66518.qm@web27907.mail.ukl.yahoo.com> ----- Original Message ---- > From: Nindi Singh > To: c++-sig at python.org > Sent: Friday, 28 December, 2007 6:35:01 PM > Subject: Re: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor > > Roman, > The output from gccxml -v is : > __________________________________________________ > #include wrapper search starts here: > /usr/share/gccxml-0.7/GCC/4.1 > #include "..." search starts here: > #include <...> search starts here: > /usr/include/c++/4.1.3 > /usr/include/c++/4.1.3/x86_64-linux-gnu > /usr/include/c++/4.1.3/backward > /usr/local/include > /usr/lib/gcc/x86_64-linux-gnu/4.1.3/include > /usr/include > End of search list. > __________________________________________________ > > The header file example.hpp is > _________________________________________________ > #ifndef TESTVECTOR > #define TESTVECTOR > #include > template std::vector; > #endif > ________________________________________________ > > The pygccxml script is > ________________________________________________ > import sys > from pygccxml import parser > from pygccxml import declarations > from pygccxml.declarations import templates > from pygccxml.declarations import type_traits > > decls = parser.parse( ['example.hpp'])#, config ) > global_ns = declarations.get_global_namespace( decls ) > > query = declarations.custom_matcher_t (lambda vec > : > templates.name(vec.name)=='vector') > vectorClass = global_ns.classes(function=query) > > def processArgument(arg): > if type_traits.is_const(arg): > return 'const > '+processArgument(type_traits.remove_const(arg)) > + ' ' > if type_traits.is_reference(arg): > return processArgument(type_traits.remove_reference(arg)) > + > '&' > if type_traits.is_pointer(arg): > return processArgument(type_traits.remove_pointer(arg)) + '*' > if type_traits.is_fundamental(arg): > return str(arg) > if type_traits.is_class(arg): > theType = type_traits.remove_declarated(arg) > return theType.demangled > if type_traits.is_class_declaration(arg): > theType = type_traits.remove_declarated(arg) > return theType.demangled > > for class_ in vectorClass: > theConstructors = class_.constructors() > for c in theConstructors: > print '\n\n' > print 'name :',c.demangled > print 'location :',c.location.file_name > if len(c.required_args)==0: > print 'No required args' > else : > print 'required args:' > for a in c.required_args: > print ' ',processArgument(a.type) > if len(c.optional_args)==0: > print 'No optional args' > else : > print 'optional args:' > for a in c.optional_args: > print ' ',processArgument(a.type) > ______________________________________________________________________ > INFO Parsing source file "example.hpp" ... > > INFO gccxml cmd: /usr/bin/gccxml -I"." > "example.hpp" > -fxml="/tmp/tmpJvYj92.xml" > > name : std::vector > std::allocator > >::vector(std::allocator const&) > location : /usr/include/c++/4.1.3/bits/stl_vector.h > required args: > const std::allocator & > No optional args > > name : std::vector > std::allocator > >::vector(unsigned long, double const&, std::allocator const&) > location : /usr/include/c++/4.1.3/bits/stl_vector.h > required args: > size_t > const double & > const std::allocator & > No optional args > > name : std::vector > std::allocator > >::vector(std::vector > const&) > location : /usr/include/c++/4.1.3/bits/stl_vector.h > required args: > const std::vector > & > No optional args > The output from this script is > ____________________________________________________ > > In /usr/include/c++/4.1.3/bits/stl_vector.h > > line 202 : vector(const allocator_type& __a = allocator_type()) > line 214-215 : vector(size_type __n, const value_type& __value > = > value_type(), > const allocator_type& __a = allocator_type()) > line 232 : vector(const vector& __x) > > I just cannot figure out why the optional parameters ( allocator ) > do > not show up as optional > > Ok, I have the much more simplified header file, with similar problem. In this header file I use my own class instead of std::vector ____________________________________________________________________ #ifndef TESTVECTOR #define TESTVECTOR template class myAlloc{ typedef T type; }; template > class vector { typedef Alloc alloc; vector(const alloc & a = alloc()){} vector(unsigned long , const alloc & a =alloc()){} }; template vector; #endif __________________________________________________________________________ __________________________________________________________ Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com From nindi73 at yahoo.co.uk Fri Dec 28 22:36:26 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Fri, 28 Dec 2007 21:36:26 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <341031.61624.qm@web27908.mail.ukl.yahoo.com> In my previous 2 emails, in my c++ code I instantiated vector with template vector; This is a typo and should have read template class vector; Secondly after a little further investigation pygccxml script: ______________________________________________________________ import sys from pygccxml import parser from pygccxml import declarations from pygccxml.declarations import templates from pygccxml.declarations import type_traits decls = parser.parse( ['example.hpp'])#, config ) global_ns = declarations.get_global_namespace( decls ) query = declarations.custom_matcher_t (lambda vec : templates.name(vec.name).endswith('vector')) vectorClass = global_ns.classes(function=query) def processArgument(arg): if type_traits.is_const(arg): return 'const '+processArgument(type_traits.remove_const(arg)) + ' ' if type_traits.is_reference(arg): return processArgument(type_traits.remove_reference(arg)) + '&' if type_traits.is_pointer(arg): return processArgument(type_traits.remove_pointer(arg)) + '*' if type_traits.is_fundamental(arg): return str(arg) if type_traits.is_class(arg): theType = type_traits.remove_declarated(arg) return theType.demangled if type_traits.is_class_declaration(arg): theType = type_traits.remove_declarated(arg) return theType.demangled for class_ in vectorClass: theConstructors = class_.constructors() for c in theConstructors: print '\n\n' print 'name :',c.demangled print 'location :',c.location.file_name if len(c.required_args)==0: print 'No required args' else : print 'required args:' for a in c.required_args: print ' ',processArgument(a.type) if len(c.optional_args)==0: print 'No optional args' else : print 'optional args:' for a in c.optional_args: print ' ',processArgument(a.type) ___________________________________________________________________ c++ header file: ___________________________________________________________________ #ifndef TESTVECTOR #define TESTVECTOR class egclass{}; template class vector { vector(unsigned long i, const egclass = egclass() ){} }; class xvector { xvector(unsigned long i, const egclass = egclass() ){} }; template class vector; #endif __________________________________________________________________ The ouput is __________________________________________________________________ INFO Parsing source file "example.hpp" ... INFO gccxml cmd: /usr/bin/gccxml -I"." "example.hpp" -fxml="/tmp/tmp7BA-U2.xml" name : xvector::xvector(xvector const&) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: const xvector & No optional args name : xvector::xvector(unsigned long, egclass) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: long unsigned int optional args: const egclass name : vector::vector(vector const&) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: const vector & No optional args name : vector::vector(unsigned long, egclass) location : /b/Papa/Workspace/pygccxmlTest/example.hpp required args: long unsigned int const egclass No optional args ___________________________________________________________________ So interestingly the problem is with templated classes. Is this a problem with pygccxml or gccxml ? I'll try to look at the xml file. __________________________________________________________ Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com From nindi73 at yahoo.co.uk Fri Dec 28 23:08:42 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Fri, 28 Dec 2007 22:08:42 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <352664.18531.qm@web27915.mail.ukl.yahoo.com> ----- Original Message ---- > From: Nindi Singh > To: Development of Python/C++ integration > Sent: Friday, 28 December, 2007 9:36:26 PM > Subject: Re: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor > > In my previous 2 emails, in my c++ code I instantiated vector with > > template vector; > > This is a typo and should have read > > template class vector; > > Secondly after a little further investigation > > pygccxml script: > ______________________________________________________________ > import sys > from pygccxml import parser > from pygccxml import declarations > from pygccxml.declarations import templates > from pygccxml.declarations import type_traits > > decls = parser.parse( ['example.hpp'])#, config ) > global_ns = declarations.get_global_namespace( decls ) > > query = declarations.custom_matcher_t (lambda vec > : > templates.name(vec.name).endswith('vector')) > > vectorClass = global_ns.classes(function=query) > > def processArgument(arg): > if type_traits.is_const(arg): > return 'const > '+processArgument(type_traits.remove_const(arg)) > + ' ' > if type_traits.is_reference(arg): > return processArgument(type_traits.remove_reference(arg)) > + > '&' > if type_traits.is_pointer(arg): > return processArgument(type_traits.remove_pointer(arg)) + '*' > if type_traits.is_fundamental(arg): > return str(arg) > if type_traits.is_class(arg): > theType = type_traits.remove_declarated(arg) > return theType.demangled > if type_traits.is_class_declaration(arg): > theType = type_traits.remove_declarated(arg) > return theType.demangled > > for class_ in vectorClass: > theConstructors = class_.constructors() > for c in theConstructors: > print '\n\n' > print 'name :',c.demangled > print 'location :',c.location.file_name > if len(c.required_args)==0: > print 'No required args' > else : > print 'required args:' > for a in c.required_args: > print ' ',processArgument(a.type) > if len(c.optional_args)==0: > print 'No optional args' > else : > print 'optional args:' > for a in c.optional_args: > print ' ',processArgument(a.type) > > ___________________________________________________________________ > > c++ header file: > ___________________________________________________________________ > #ifndef TESTVECTOR > #define TESTVECTOR > > class egclass{}; > > template > class vector { > vector(unsigned long i, const egclass = egclass() ){} > }; > > class xvector { > xvector(unsigned long i, const egclass = egclass() ){} > }; > > template class vector?double?; > > #endif > > __________________________________________________________________ > The ouput is > __________________________________________________________________ > INFO Parsing source file "example.hpp" ... > > INFO gccxml cmd: /usr/bin/gccxml -I"." > "example.hpp" > -fxml="/tmp/tmp7BA-U2.xml" > > > > name : xvector::xvector(xvector const&) > location : /b/Papa/Workspace/pygccxmlTest/example.hpp > required args: > const xvector & > No optional args > > > > name : xvector::xvector(unsigned long, egclass) > location : /b/Papa/Workspace/pygccxmlTest/example.hpp > required args: > long unsigned int > optional args: > const egclass > > > > name : vector::vector(vector const&) > location : /b/Papa/Workspace/pygccxmlTest/example.hpp > required args: > const vector & > No optional args > > > > name : vector::vector(unsigned long, egclass) > location : /b/Papa/Workspace/pygccxmlTest/example.hpp > required args: > long unsigned int > const egclass > No optional args > > ___________________________________________________________________ > > So interestingly the problem is with templated classes. > Is this a problem with pygccxml or gccxml ? > I'll try to look at the xml file. > > More progress. I firstly checked out and built gccxml from cvs. I then tried the same excerises as in my previous emails and got the same results. Also I had a look at the resulting xml file from running gcccxml on example.hpp in my last email. These two lines looked intersting : _____________________________________________________________________________________________________ ______________________________________________________________________________________________________ The default values look interesting. gccxml does pick up that there is a default value for the second parameter of the constructor in both the templated and non-templated classes. However <gccxml-cast-expr> is something I do not understand, it should be the same as egclass() I suspect. pygccxml does not pick this up at all and it doesn't show there being a default value where there is one. ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/ From Bruce_Sherwood at ncsu.edu Sat Dec 29 06:47:09 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Sat, 29 Dec 2007 00:47:09 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4773C17B.4050802@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> Message-ID: <4775DF5D.3030400@ncsu.edu> I realized belatedly that I should upgrade from Boost 1.33 to 1.34. Alas, that didn't cure my problem. Bruce Sherwood Bruce Sherwood wrote: > I should have added: This structure worked with the older version of > VPython which used Numeric, but it doesn't work in the beta version > which uses numpy. Since I don't know enough about either numpy or Boost, > I'm left guessing which subsystem is the source of my difficulties, and > clueless about how to remedy them. > > Bruce Sherwood > > Bruce Sherwood wrote: > >> Thanks for the comment, which limits the range of possible solutions. >> The VPython vector class is implemented in C++, not in Python. I made up >> the simple test in my previous note to try out the solution that had >> been offered and which you have usefully ruled out. Here is the relevant >> part of the vector class, which indeed doesn't look like an ndarray: >> >> inline vector >> operator*( const double s) const throw() >> { return vector( s*x, s*y, s*z); } >> >> and here is the free function for right multiplication: >> >> inline vector >> operator*( const double& s, const vector& v) >> { return vector( s*v.x, s*v.y, s*v.z); } >> >> Maybe the unsolvable problem is in the Boost definitions: >> >> py::class_("vector", py::init< py::optional> double> >()) >> .def( self * double()) >> .def( double() * self) >> >> Left multiplication is fine, but right multiplication isn't. >> >> Bruce Sherwood >> >> Robert Kern wrote: >> >> >>> Bruce Sherwood wrote: >>> >>> >>> >>>> Thanks for the suggestion. It hadn't occurred to me to try to override >>>> numpy as you suggest. However, when I try the code shown below as the >>>> start of a test of this scheme, I get the following error: >>>> >>>> Traceback (most recent call last): >>>> File "C:\Documents and Settings\Bruce\My >>>> Documents\0VPythonWork\vectors.py", line 24, in >>>> numpy.float64.__mul__ = new_mul >>>> TypeError: can't set attributes of built-in/extension type 'numpy.float64' >>>> >>>> I'm copying this to the numpy discussion list, as maybe someone there >>>> will see where to go starting from your suggestion. >>>> >>>> >>>> >>> Like most (or all) builtin-types, the numpy float scalars do not permit >>> replacing their methods from Python. >>> >>> I'm not familiar with vpython's vector. If you can make it "not look like an >>> ndarray", then you should be able to just implement __rmul__ on vector. >>> >>> >>> >>> >> _______________________________________________ >> Numpy-discussion mailing list >> Numpy-discussion at scipy.org >> http://projects.scipy.org/mailman/listinfo/numpy-discussion >> >> > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > From nindi73 at yahoo.co.uk Sat Dec 29 09:36:14 2007 From: nindi73 at yahoo.co.uk (Nindi Singh) Date: Sat, 29 Dec 2007 08:36:14 +0000 (GMT) Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor Message-ID: <156302.24452.qm@web27915.mail.ukl.yahoo.com> Issue is now resolved. For explanation see the gccxml at gccxml.org mailing list for discussion with subject: Default parameter values in member functions of templated classes Brad King has checked in a bug fix which I have checked out from cvs on 29/12/2007 and it is working as expected. N ___________________________________________________________ Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now. http://uk.answers.yahoo.com/ From roman.yakovenko at gmail.com Sat Dec 29 19:41:20 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 29 Dec 2007 20:41:20 +0200 Subject: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor In-Reply-To: <156302.24452.qm@web27915.mail.ukl.yahoo.com> References: <156302.24452.qm@web27915.mail.ukl.yahoo.com> Message-ID: <7465b6170712291041t17664c30ge9040f71cfb4b754@mail.gmail.com> On Dec 29, 2007 10:36 AM, Nindi Singh wrote: > Issue is now resolved. For explanation see the gccxml at gccxml.org mailing list for discussion with subject: > > > Default parameter values in member functions > of templated classes > > Brad King has checked in a bug fix which I have checked out from cvs on 29/12/2007 and it is working as expected. Wow, it was quick. Thanks for informing me. I will add this to my unit tests suite -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Dec 29 19:47:16 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 29 Dec 2007 20:47:16 +0200 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4775DF5D.3030400@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> Message-ID: <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> On Dec 29, 2007 7:47 AM, Bruce Sherwood wrote: > I realized belatedly that I should upgrade from Boost 1.33 to 1.34. > Alas, that didn't cure my problem. Can you post small and complete example of what you are trying to achieve? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From roman.yakovenko at gmail.com Sat Dec 29 19:48:45 2007 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Sat, 29 Dec 2007 20:48:45 +0200 Subject: [C++-sig] Exposing C Array members to python using boost In-Reply-To: References: Message-ID: <7465b6170712291048sd30f5aci82771c45033f258b@mail.gmail.com> On Dec 28, 2007 8:02 PM, Carpman, David wrote: > Thanks very much for the reply, Roman. I tried Py++ and it indeed automatically handles the case I outlined above concerning C-array members, and with much less tedious writing of registration code. I also found it convenient to use to insert some other C++ code for each of my structures that normally I wrote by hand. The API docs and examples on your webpage were very helpful. > > Warm regards, Thanks. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ From Bruce_Sherwood at ncsu.edu Sat Dec 29 21:41:53 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Sat, 29 Dec 2007 15:41:53 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> Message-ID: <4776B111.9020607@ncsu.edu> Roman Yakovenko wrote: > On Dec 29, 2007 7:47 AM, Bruce Sherwood wrote: > >> I realized belatedly that I should upgrade from Boost 1.33 to 1.34. >> Alas, that didn't cure my problem. >> > Can you post small and complete example of what you are trying to achieve? > I don't have a "small and complete" example available, but I'll summarize from earlier posts. VPython (vpython.org) has its own vector class to mimic the properties of 3D vectors used in physics, in the service of easy creation of 3D animations. There is a beta version which imports numpy and uses it internally; the older production version uses Numeric. Boost python and thread libraries are used to connect the C++ VPython code to Python. There is operator overloading that includes scalar*vector and vector*scalar, both producing vector. With Numeric, sqrt produced a float, which was a scalar for the operator overloading. With numpy, sqrt produces a numpy.float64 which is caught by vector*scalar but not by scalar*vector, which means that scalar*vector produces an ndarray rather than a vector, which leads to a big performance hit in existing VPython programs. The overloading and Boost code is the same in the VPython/Numeric and VPython/numpy versions. I don't know whether the problem is with numpy or with Boost or with the combination of the two. Here is the relevant part of the vector class: inline vector operator*( const double s) const throw() { return vector( s*x, s*y, s*z); } and here is the free function for right multiplication: inline vector operator*( const double& s, const vector& v) { return vector( s*v.x, s*v.y, s*v.z); } Maybe the problem is in the Boost definitions: py::class_("vector", py::init< py::optional >()) .def( self * double()) .def( double() * self) Left multiplication is fine, but right multiplication isn't. A colleague suggested the following Boost declarations but cautioned that he wasn't sure of the syntax for referring to operator, and indeed this doesn't compile: .def( "__mul__", &vector::operator*(double), "Multiply vector times scalar") .def( "__rmul__", &operator*(const double&, const vector&), "Multiply scalar times vector") I would really appreciate a Boost or numpy expert being able to tell me what's wrong (if anything) with these forms. However, I may have a useful workaround as I described in a post to the numpy discussion list. A colleague suggested that I do something like this for sqrt and other such mathematical functions: def sqrt(x): try: return mathsqrt(x) except TypeError: return numpysqrt(x) That is, first try the simple case of a scalar argument, handled by the math module sqrt, and only use the numpy sqrt routine in the case of an array argument. Even with the overhead of the try/except machinery, one gets must faster square roots for scalar arguments this way than with the numpy sqrt. Bruce Sherwood From Bruce_Sherwood at ncsu.edu Sat Dec 29 23:02:36 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Sat, 29 Dec 2007 17:02:36 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4776B111.9020607@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> <4776B111.9020607@ncsu.edu> Message-ID: <4776C3FC.7030101@ncsu.edu> I found by timing measurements that a faster scheme with less penalty for the case of sqrt(array) looks like this: def sqrt(x): if type(x) is float: return mathsqrt(x) return numpysqrt(x) Bruce Sherwood wrote: > Roman Yakovenko wrote: >> On Dec 29, 2007 7:47 AM, Bruce Sherwood wrote: >> >>> I realized belatedly that I should upgrade from Boost 1.33 to 1.34. >>> Alas, that didn't cure my problem. >>> >> Can you post small and complete example of what you are trying to >> achieve? >> > I don't have a "small and complete" example available, but I'll > summarize from earlier posts. VPython (vpython.org) has its own vector > class to mimic the properties of 3D vectors used in physics, in the > service of easy creation of 3D animations. There is a beta version > which imports numpy and uses it internally; the older production > version uses Numeric. Boost python and thread libraries are used to > connect the C++ VPython code to Python. > > There is operator overloading that includes scalar*vector and > vector*scalar, both producing vector. With Numeric, sqrt produced a > float, which was a scalar for the operator overloading. With numpy, > sqrt produces a numpy.float64 which is caught by vector*scalar but not > by scalar*vector, which means that scalar*vector produces an ndarray > rather than a vector, which leads to a big performance hit in existing > VPython programs. The overloading and Boost code is the same in the > VPython/Numeric and VPython/numpy versions. I don't know whether the > problem is with numpy or with Boost or with the combination of the two. > > Here is the relevant part of the vector class: > > inline vector > operator*( const double s) const throw() > { return vector( s*x, s*y, s*z); } > > and here is the free function for right multiplication: > > inline vector > operator*( const double& s, const vector& v) > { return vector( s*v.x, s*v.y, s*v.z); } > > Maybe the problem is in the Boost definitions: > > py::class_("vector", py::init< py::optional double> >()) > .def( self * double()) > .def( double() * self) > > Left multiplication is fine, but right multiplication isn't. > > A colleague suggested the following Boost declarations but cautioned > that he wasn't sure of the syntax for referring to operator, and > indeed this doesn't compile: > > .def( "__mul__", &vector::operator*(double), "Multiply vector times > scalar") > .def( "__rmul__", &operator*(const double&, const vector&), "Multiply > scalar times vector") > > I would really appreciate a Boost or numpy expert being able to tell > me what's wrong (if anything) with these forms. However, I may have a > useful workaround as I described in a post to the numpy discussion > list. A colleague suggested that I do something like this for sqrt and > other such mathematical functions: > > def sqrt(x): > try: return mathsqrt(x) > except TypeError: return numpysqrt(x) > > That is, first try the simple case of a scalar argument, handled by > the math module sqrt, and only use the numpy sqrt routine in the case > of an array argument. Even with the overhead of the try/except > machinery, one gets must faster square roots for scalar arguments this > way than with the numpy sqrt. > > Bruce Sherwood > From Bruce_Sherwood at ncsu.edu Sun Dec 30 00:00:53 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Sat, 29 Dec 2007 18:00:53 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4776C3FC.7030101@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <7465b6170712252340o159aa52qe1dae3707e3ab625@mail.gmail.com> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> <4776B111.9020607@ncsu.edu> <4776C3FC.7030101@ncsu.edu> Message-ID: <4776D1A5.60106@ncsu.edu> Okay, I've implemented the scheme below that was proposed by Scott Daniels on the VPython mailing list, and it solves my problem. It's also much faster than using numpy directly: even with the "def "and "if" overhead: sqrt(scalar) is over 3 times faster than the numpy sqrt, and sqrt(array) is very nearly as fast as the numpy sqrt. Thanks to those who made suggestions. There remains the question of why operator overloading of the kind I've described worked with Numeric and Boost but not with numpy and Boost. There is also the question of whether it would pay for numpy to make what is probably an exceedingly fast check and do much faster calculations of sqrt(scalar) and other such mathematical functions. Bruce Sherwood Bruce Sherwood wrote: > I found by timing measurements that a faster scheme with less penalty > for the case of sqrt(array) looks like this: > > def sqrt(x): > if type(x) is float: return mathsqrt(x) > return numpysqrt(x) > > Bruce Sherwood wrote: > >> Roman Yakovenko wrote: >> >>> On Dec 29, 2007 7:47 AM, Bruce Sherwood wrote: >>> >>> >>>> I realized belatedly that I should upgrade from Boost 1.33 to 1.34. >>>> Alas, that didn't cure my problem. >>>> >>>> >>> Can you post small and complete example of what you are trying to >>> achieve? >>> >>> >> I don't have a "small and complete" example available, but I'll >> summarize from earlier posts. VPython (vpython.org) has its own vector >> class to mimic the properties of 3D vectors used in physics, in the >> service of easy creation of 3D animations. There is a beta version >> which imports numpy and uses it internally; the older production >> version uses Numeric. Boost python and thread libraries are used to >> connect the C++ VPython code to Python. >> >> There is operator overloading that includes scalar*vector and >> vector*scalar, both producing vector. With Numeric, sqrt produced a >> float, which was a scalar for the operator overloading. With numpy, >> sqrt produces a numpy.float64 which is caught by vector*scalar but not >> by scalar*vector, which means that scalar*vector produces an ndarray >> rather than a vector, which leads to a big performance hit in existing >> VPython programs. The overloading and Boost code is the same in the >> VPython/Numeric and VPython/numpy versions. I don't know whether the >> problem is with numpy or with Boost or with the combination of the two. >> >> Here is the relevant part of the vector class: >> >> inline vector >> operator*( const double s) const throw() >> { return vector( s*x, s*y, s*z); } >> >> and here is the free function for right multiplication: >> >> inline vector >> operator*( const double& s, const vector& v) >> { return vector( s*v.x, s*v.y, s*v.z); } >> >> Maybe the problem is in the Boost definitions: >> >> py::class_("vector", py::init< py::optional> double> >()) >> .def( self * double()) >> .def( double() * self) >> >> Left multiplication is fine, but right multiplication isn't. >> >> A colleague suggested the following Boost declarations but cautioned >> that he wasn't sure of the syntax for referring to operator, and >> indeed this doesn't compile: >> >> .def( "__mul__", &vector::operator*(double), "Multiply vector times >> scalar") >> .def( "__rmul__", &operator*(const double&, const vector&), "Multiply >> scalar times vector") >> >> I would really appreciate a Boost or numpy expert being able to tell >> me what's wrong (if anything) with these forms. However, I may have a >> useful workaround as I described in a post to the numpy discussion >> list. A colleague suggested that I do something like this for sqrt and >> other such mathematical functions: >> >> def sqrt(x): >> try: return mathsqrt(x) >> except TypeError: return numpysqrt(x) >> >> That is, first try the simple case of a scalar argument, handled by >> the math module sqrt, and only use the numpy sqrt routine in the case >> of an array argument. Even with the overhead of the try/except >> machinery, one gets must faster square roots for scalar arguments this >> way than with the numpy sqrt. >> >> Bruce Sherwood >> >> > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at scipy.org > http://projects.scipy.org/mailman/listinfo/numpy-discussion > From wilson.max at gmail.com Sun Dec 30 18:26:49 2007 From: wilson.max at gmail.com (Maximilian Wilson) Date: Sun, 30 Dec 2007 09:26:49 -0800 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <4776D1A5.60106@ncsu.edu> References: <4771F0AE.40406@ncsu.edu> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> <4776B111.9020607@ncsu.edu> <4776C3FC.7030101@ncsu.edu> <4776D1A5.60106@ncsu.edu> Message-ID: <2ddbda5f0712300926n7a1a939ai7c06ce8f7eb4cc07@mail.gmail.com> On Dec 29, 2007 3:00 PM, Bruce Sherwood wrote: > Thanks to those who made suggestions. There remains the question of why > operator overloading of the kind I've described worked with Numeric and > Boost but not with numpy and Boost. There is also the question of > whether it would pay for numpy to make what is probably an exceedingly > fast check and do much faster calculations of sqrt(scalar) and other > such mathematical functions. I think the problem you ran into with Numeric has to do with Python's optimizations for built-ins. In order to override members of e.g. class "dict," you have to provide a trivial subclass (or do something funny with a metaclass) because, I think, otherwise Python hard-wires method calls to the extension method instead of looking them up in __dict__. That's about all I know on the subject, unfortunately, but here's Guido on this issue: http://mail.python.org/pipermail/python-dev/2003-November/040070.html -Max -- "The presentation or 'gift' of the Holy Ghost simply confers upon a man the right to receive at any time, when he is worthy of it and desires it, the power and light of truth of the Holy Ghost, although he may often be left to his own spirit and judgment." --Joseph F. Smith (manual, p. 69) Be pretty if you are, Be witty if you can, But be cheerful if it kills you. From Bruce_Sherwood at ncsu.edu Sun Dec 30 19:17:26 2007 From: Bruce_Sherwood at ncsu.edu (Bruce Sherwood) Date: Sun, 30 Dec 2007 13:17:26 -0500 Subject: [C++-sig] [Numpy-discussion] Overloading sqrt(5.5)*myvector In-Reply-To: <2ddbda5f0712300926n7a1a939ai7c06ce8f7eb4cc07@mail.gmail.com> References: <4771F0AE.40406@ncsu.edu> <47732B84.70400@ncsu.edu> <4773325D.3040907@gmail.com> <4773BD97.1000703@ncsu.edu> <4773C17B.4050802@ncsu.edu> <4775DF5D.3030400@ncsu.edu> <7465b6170712291047k2933ceb5o20a0faad77bd85c0@mail.gmail.com> <4776B111.9020607@ncsu.edu> <4776C3FC.7030101@ncsu.edu> <4776D1A5.60106@ncsu.edu> <2ddbda5f0712300926n7a1a939ai7c06ce8f7eb4cc07@mail.gmail.com> Message-ID: <4777E0B6.5030002@ncsu.edu> That doesn't sound like my problem. In VPython it's not that its vector class overrides a Python class. Rather there is overloading of operators involving the vector class. The rules for doing this in C++ and Boost worked with Numeric but not with numpy. It's not clear whether the problem is with Boost or numpy. Bruce Sherwood Maximilian Wilson wrote: > On Dec 29, 2007 3:00 PM, Bruce Sherwood wrote: > >> Thanks to those who made suggestions. There remains the question of why >> operator overloading of the kind I've described worked with Numeric and >> Boost but not with numpy and Boost. There is also the question of >> whether it would pay for numpy to make what is probably an exceedingly >> fast check and do much faster calculations of sqrt(scalar) and other >> such mathematical functions. >> > > I think the problem you ran into with Numeric has to do with Python's > optimizations for built-ins. In order to override members of e.g. > class "dict," you have to provide a trivial subclass (or do something > funny with a metaclass) because, I think, otherwise Python hard-wires > method calls to the extension method instead of looking them up in > __dict__. That's about all I know on the subject, unfortunately, but > here's Guido on this issue: > > http://mail.python.org/pipermail/python-dev/2003-November/040070.html > > -Max > > >