<br><div><span class="gmail_quote">On 5/3/07, <b class="gmail_sendername">Albert Strasheim</b> <<a href="mailto:fullung@gmail.com">fullung@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, 02 May 2007, Roman Yakovenko wrote:<br><br>> On 5/2/07, Eric Jonas <jonas at <a href="http://mit.edu">mit.edu</a>> wrote:<br>> > Hello! I'm using boost::python to try and interface numpy (that is, the
<br>> > newest numpy, not numeric or numarray) ndarray objects to my code which<br>> > depends on boost::multi_array. I've written functions that take a<br>> > pyobject* and return a multiarray and vice versa. Now I'm at the point
<br>> > of interfacing my c++ classes (which take multi_array references in<br>> > their constructors). Rather than adulterating their interfaces by adding<br>> > additional constructors with PyObject* arguments, is there some way of
<br>> > telling boost::python to use my conversion functions automatically?<br>><br>> <a href="http://www.language-binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/automatic_conversion.html">http://www.language-binding.net/pyplusplus/troubleshooting_guide/automatic_conversion/automatic_conversion.html
</a><br>><br>> Let me know if this helped you.<br><br>As luck would have it, I also started playing with this idea yesterday<br>and I found the above-mentioned page to help me along. I'm mostly<br>interested in wrapping an interface written in terms of uBLAS vectors,
<br>matrices and vector-of-vectors.</blockquote><div><br>:-), good <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;">One issue I've run into with uBLAS is that there doesn't seem to be an
<br>array adaptor (the A in matrix<T, L, A>) that can be used to wrap<br>existing memory without copying at some point. Writing an array adaptor<br>like this shouldn't be too hard though.</blockquote><div><br>You don't have, use indexing suite v2:
<br><a href="http://language-binding.net/pyplusplus/documentation/containers.html">http://language-binding.net/pyplusplus/documentation/containers.html</a><br>And example of usage:<br><a href="http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range">
http://language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range</a><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Another issue is that you have to be very careful with the<br>vector/matrix type you use, since converting a NumPy array to<br>matrix<T, L, adapter_that_doesnt_copy<T> > and passing that to a<br>function that expects matrix<T> doesn't work (strange crashes, probably
<br>due to the slight difference in size between the objects, due to the<br>different array adaptors being used).<br><br>Anyway, I've more or less got pass-by-value and return-by-value working<br>using Roman's example, but I can't quite figure out how to make
<br>Boost.Python convert pointer and reference arguments or return values<br>into PyObject*'s using the same scheme. Should this just work if I have<br>my automatic conversion set up correctly, or is there additional magic
<br>that needs to be added? Again, it would be *very* useful if copying<br>could be avoided here.</blockquote><div><br>Post small example, may be I will be able to help<br></div><br></div>-- <br>Roman Yakovenko<br>C++ Python language binding
<br><a href="http://www.language-binding.net/">http://www.language-binding.net/</a>