[SciPy-user] about using python class in weave

eric jones eric at enthought.com
Mon Sep 23 16:03:20 EDT 2002


Instance conversion isn't supported in the released version, but the CVS
version handles it.  CVS also has limited support for working with
attributes.  I'm in the process of augmenting SCXX for this sort of
thing.  Support for calling methods (what you want) hasn't been added
yet, but probably will appear within the next week or so.  

It's worth noting that, unless your Python class is a wrapper around a
C++ class (using SWIG or boost or whatever), the performance is going to
be lousy for this because it has to call back into Python.  It's
actually worse than Python because of the overhead in the C++ classes
used to represent Pyhon objects (perhaps this can be reduced).  

So, if your app needs to access the python class information within a
computational loop, weave isn't going to help much.  However, if you can
do something like:

	a = s.blah()
      weave.inline("<do something time consuming with a>", ['a'])

then you could get big wins.

To get back to the same speed as Python (possibly even 10-100% faster
actually), you can manipulate py_s instead of s.  py_s is a raw
PyObject* and you can use the Python C API on this guy until your hearts
content.

The other option is to tackle the problem of writing type converters
that are based on the boost library.  This library is a lot more complex
than SCXX (which we use now), but it is also more powerful.  Something
along the lines of what you want is probably likely using it.

Regards,
Eric

> -----Original Message-----
> From: scipy-user-admin at scipy.net [mailto:scipy-user-admin at scipy.net]
On
> Behalf Of Yijue Hou
> Sent: Monday, September 23, 2002 1:51 PM
> To: scipy-user at scipy.net
> Subject: [SciPy-user] about using python class in weave
> 
> weave.inline call use python integers directly,
> but while I tried to use python classes, it doesn't work.
> 
> suppose s is a python class,
> my code:
> weave.inline("s.blah();",['s'])
> 
> it said it unable to convert to c++ types, so how to call python
> classes in c function using  weave?
> 
> Thanks
> 
> 
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list