[C++-sig] Boost.Python: wrapping classes instead of functions???

2009-09-10 Thread David Roy

Hi,

I'm facing a very strange behavior that I cannot manage to explane.
I'm currently working on a project of re-implementing Python functions in
C++ in order to improve performance and I'm then creating Python extensions
thanks to Boost.
I implemented quite a heavy function that calculates tangents and binormals
this way:

class GeomUtils
{
private:
// some functions...
public:
AddTangentAndBinormals();
}

GeomUtils::AddtangentAndBinormals()
{
// call some functions...
}

BOOST_PYTHON_MODULE(geom_utils)
{
class_("GeomUtils", init<>())
.def("AddTangentAndBinormals", &GeomUtils::AddTangentAndBinormals)
;
}

This was very successful, decreasing the computation time from 54.0 seconds
to less than 1.0 second.
Then I decided this wasn't worth a class and that I should directly export
the function :

AddTangentAndBinormals()
{
// call some functions...
}

BOOST_PYTHON_MODULE(geom_utils)
{
def("AddTangentAndBinormals", &AddTangentAndBinormals);
}

and the profile was back to 54.0 seconds!!!
Please could someone help me understand what's the difference and the
mechanism underlying that?

Thanks
-David
-- 
View this message in context: 
http://www.nabble.com/Boost.Python%3A-wrapping-classes-instead-of-functionstp25380730p25380730.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Subset of default python library

2009-09-10 Thread Nat Goodspeed

Mark Chandler wrote:

Is there a small subset of the default python library that i can use for 
our embedded instance. Since this is part of a larger app that doesnt 
expect to have python installed thus we are including it with the 
program data. How ever there is alot of stuff in there that we are not 
going to use (all the server stuff) and dont want clients using as 
well.


Have you looked at the distutils tools? I know there's functionality to 
start from a "root set" of referenced Python library modules and produce 
an exhaustive list of recursively-referenced modules.


I haven't directly used those tools myself because my experience is more 
with py2exe and py2app:

http://www.py2exe.org/
http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html

In our case, instead of embedding the Python interpreter into our C++ 
application, we started with a Python main program and wrapped our C++ 
code as extension modules. This structure works well with py2exe and py2app.


Both tools package the minimum subset of the Python standard library 
needed for your specific application, and that functionality is 
available via distutils.

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Boost.Python: wrapping classes instead of functions???

2009-09-10 Thread troy d. straszheim

David Roy wrote:


and the profile was back to 54.0 seconds!!!
Please could someone help me understand what's the difference and the
mechanism underlying that?


Probably that you're not running the code that you think you are.  There 
should be no difference between member function and free function in 
this case, unless you're not telling us something.  Run python with the 
-v option to be sure that the code you are running comes from where you 
expect it to.


-t



___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Subset of default python library

2009-09-10 Thread troy d. straszheim

Nat Goodspeed wrote:

Mark Chandler wrote:

Is there a small subset of the default python library that i can use 
for our embedded instance. Since this is part of a larger app that 
doesnt expect to have python installed thus we are including it with 
the program data. How ever there is alot of stuff in there that we are 
not going to use (all the server stuff) and dont want clients using as 
well.


Have you looked at the distutils tools? I know there's functionality to 
start from a "root set" of referenced Python library modules and produce 
an exhaustive list of recursively-referenced modules.


You can also try running python with the -v flag, it will give you a 
list of everything it imports.  You probably can get your minimum 
distribution from this info...


-t
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig