On 4/19/07, <b class="gmail_sendername">Stou Sandalski</b> <<a href="mailto:stou.sandalski@gmail.com">stou.sandalski@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for the reply,<br><br>That is what I am doing now, the problem is that I need the code to be<br>in C/C++ inside the wrapper.  I am creating a lot of these objects and<br>each time I am iterating over ~1.4 million points... and in python
<br>it's quite slow.... which is unpleasant especially since it's such a<br>trivial operation.  My calculation's in NumPy take seconds, and to<br>create an object for visualization I have to wait 2 minutes. =(
</blockquote><div><br>You can define function that first argument is a reference to the instance of your class.<br>Then you can register it as usual function.<br>For example: <br><a href="http://language-binding.net/pyplusplus/documentation/functions/transformation/built_in/input_c_buffer.html">
http://language-binding.net/pyplusplus/documentation/functions/transformation/built_in/input_c_buffer.html</a><br>take a look on generated source code( at the bottom of the page )<br> </div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks again,<br><br>Stou<br><br>On 4/19/07, Roman Yakovenko <<a href="mailto:roman.yakovenko@gmail.com">roman.yakovenko@gmail.com</a>> wrote:<br>> On 19 Apr 2007 00:37:36 -0700, Stou Sandalski <<a href="mailto:stou.sandalski@gmail.com">
stou.sandalski@gmail.com</a>><br>> wrote:<br>> > Hi,<br>> ><br>> > I have a python library created by wrapping the C++ library using<br>> > Boost.Python, the problem is that the wrappers are not very
<br>> > pythonic.... so I want to add some methods that do not exist in the C+<br>> > + implementation, that would create a better Python interface.<br>> ><br>> > For example to initialize the data in an object in the library one
<br>> > must iterate through every point, setting a value for each<br>> > individually.  That's the way it works in C++ but in python it would<br>> > be nice to instead just have one call that can receive a numpy array
<br>> > or a tuple. I want to add a call like: setData(array) to the python<br>> > object, a call that does not exist in the C++ implementation and then<br>> > in the C++ wrappers actually use setData to iterate through the array
<br>> > and set the values using the normal C++ method, say setValue(index,<br>> > value).<br>> ><br>> > Something along the lines of this (initData is not in the constructor<br>> > on purpose) C++ object:
<br>> ><br>> > class Foo<br>> > {<br>> > public:<br>> >      void initData(int size)<br>> >      {<br>> >         data = new float[size];<br>> >      }; // Create the data array
<br>> >      void setValue(int index, float value) // Set given value<br>> >      {<br>> >          data[index] = value;<br>> >      }<br>> > private:<br>> >      float *data;<br>> > };
<br>> ><br>> ><br>> > In python however I want to do this:<br>> ><br>> > obj = foo()<br>> > ar = array([1,2,3,4,5], dtype=float)<br>> ><br>> > foo.setData(ar)<br>> ><br>
> > Or even better:<br>> ><br>> > ar = array([1,2,3,4,5], dtype=float)<br>> > obj = foo(ar)<br>> ><br>> > And have it somehow call initData() and setValue() iteration inside<br>> > the C++ code of the wrapper.  I've only used SWIG and don't really
<br>> > know much about Boost, I am not even sure how to label what I am<br>> > trying to do.<br>> ><br>> > Can this be done with Boost, without changing the C++ library?<br>><br>> Take a look on next link:
<br>> <a href="http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python">http://boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python
</a><br>><br>> > Regards,<br>> ><br>> > Stou<br>> ><br>> > --<br>> > <a href="http://mail.python.org/mailman/listinfo/python-list">http://mail.python.org/mailman/listinfo/python-list
</a><br>> ><br>><br>><br>><br>> --<br>> Roman Yakovenko<br>>  C++ Python language binding<br>> <a href="http://www.language-binding.net/">http://www.language-binding.net/</a><br></blockquote></div>
<br><br clear="all"><br>-- <br>Roman Yakovenko<br>C++ Python language binding<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>