<br><div><span class="gmail_quote">On 5/3/07, <b class="gmail_sendername">Albert Strasheim</b> &lt;<a href="mailto:fullung@gmail.com">fullung@gmail.com</a>&gt; 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>&gt; On 5/2/07, Eric Jonas &lt;jonas at <a href="http://mit.edu">mit.edu</a>&gt; wrote:<br>&gt; &gt; Hello! I&#39;m using boost::python to try and interface numpy (that is, the
<br>&gt; &gt; newest numpy, not numeric or numarray) ndarray objects to my code which<br>&gt; &gt; depends on boost::multi_array. I&#39;ve written functions that take a<br>&gt; &gt; pyobject* and return a multiarray and vice versa. Now I&#39;m at the point
<br>&gt; &gt; of interfacing my c++ classes (which take multi_array references in<br>&gt; &gt; their constructors). Rather than adulterating their interfaces by adding<br>&gt; &gt; additional constructors with PyObject* arguments, is there some way of
<br>&gt; &gt; telling boost::python to use my conversion functions automatically?<br>&gt;<br>&gt; <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>&gt;<br>&gt; 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&#39;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&#39;ve run into with uBLAS is that there doesn&#39;t seem to be an
<br>array adaptor (the A in matrix&lt;T, L, A&gt;) that can be used to wrap<br>existing memory without copying at some point. Writing an array adaptor<br>like this shouldn&#39;t be too hard though.</blockquote><div><br>You don&#39;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>&nbsp;</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&lt;T, L, adapter_that_doesnt_copy&lt;T&gt; &gt; and passing that to a<br>function that expects matrix&lt;T&gt; doesn&#39;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&#39;ve more or less got pass-by-value and return-by-value working<br>using Roman&#39;s example, but I can&#39;t quite figure out how to make
<br>Boost.Python convert pointer and reference arguments or return values<br>into PyObject*&#39;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>