<div dir="ltr">On Sat, Dec 7, 2013 at 8:25 PM, Zhenwei Luo <span dir="ltr">&lt;<a href="mailto:tluozhenwei@gmail.com" target="_blank">tluozhenwei@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">        I am writing a refinement program using the cctbx. I have encountered with a problem when I wanted to pass an array between c++ and python. The type of array I used in my c++ source file is af::shared&lt;af::shared&lt;vec3&gt; &gt;, I would like to pass it into my python script, thus I could do some other operations to this array.<br>


I wrote a method in my class to return this array.<br>
<br>
 af::shared&lt;af::shared&lt;vec3&lt;double&gt; &gt; return_modes( ) { return modes; }<br>
<br>
I wrote another method in the *_ext file to wrap this method to make it callable from python.<br>
<br>
.def(&quot;return_modes&quot;, &amp;nm_init::return_modes)<br>
<br>
But when I use it in python,<br>
eigenvector = nm_init_manager.return_modes()<br>
It gave me an error:<br>
TypeError: No to_python (by-value) converter found for c++ type: scitbx::af::shared&lt;scitbx::af::shared&lt;scitbx::vec3&lt;double&gt; &gt; &gt;<br></blockquote><div><br></div><div>What that error means is that boost.python doesn&#39;t know how to present this new type to Python.  For the data structures that we pass back and forth, we have to explicitly provide wrappers for them - including new instantiations of scitbx::array_family templates.</div>

<div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
What I want to realize is just creating an two dimensional array using vec3 as its element. I can also using the select method  in this array to select some elements from its column, just like in the af::shared&lt;vec3&lt;double&gt; &gt; array. Namely, the column of this array should have some same properties like af::shared&lt;vec3&lt;double&gt; &gt;. Can anyone help me figure out what I should do?<br>

</blockquote><div><br></div><div>In general the scitbx::array_family templates aren&#39;t really intended to every be multidimensional; for inherently 2D and 3D data types like images and maps, we use flex.grid to provide a multi-dimensional accessor on top of the 1D array.  The grid may not be the most appropriate in your case but if I&#39;m making the correct assumptions about the data you&#39;re trying to pass back and forth, I think it might be easiest to simply define a custom class that contains a std::vector of af::shared&lt;vec3&gt; arrays, and add an index parameter to the return_modes method, which would be modified to return only a single array of modes at a time.  You can also do things like wrapping a method as __getitem__ with boost.python, which would mimic a 2D array.  (I can probably dig up/cook up some code examples tomorrow if this is unclear, since it was certainly not intuitive to me when I started working with CCTBX and it would be nice to have documentation for the future.)</div>

<div><br></div><div>-Nat</div></div></div></div>