<div dir="ltr">Hi Nat,<div>  Thanks for your reply! I have tried the first method you mentioned--adding an index value to the return method. It did work if I only needed a single array for future calculation. But I found it&#39;s not very convenient for my program. It&#39;s convenient and more efficient if other classes in it could process all the one-dimensional arrays at the same time. Otherwise, I needed to write more control code in python, and the c++ part could only deal with a single array now. Therefore, I hoped that I could pass such a multidimensional array in my program.</div>

<div><br></div><div>Sincerely,</div><div>Zhenwei</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Dec 8, 2013 at 2:00 PM,  <span dir="ltr">&lt;<a href="mailto:cctbxbb-request@phenix-online.org" target="_blank">cctbxbb-request@phenix-online.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send cctbxbb mailing list submissions to<br>
        <a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://phenix-online.org/mailman/listinfo/cctbxbb" target="_blank">http://phenix-online.org/mailman/listinfo/cctbxbb</a><br>
or, via email, send a message with subject or body &#39;help&#39; to<br>
        <a href="mailto:cctbxbb-request@phenix-online.org">cctbxbb-request@phenix-online.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:cctbxbb-owner@phenix-online.org">cctbxbb-owner@phenix-online.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than &quot;Re: Contents of cctbxbb digest...&quot;<br>
<br>
<br>
Today&#39;s Topics:<br>
<br>
   1. Passing array between python and C++ (Zhenwei Luo)<br>
   2. Re: Passing array between python and C++ (Nathaniel Echols)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sat, 7 Dec 2013 22:25:08 -0600<br>
From: Zhenwei Luo &lt;<a href="mailto:tluozhenwei@gmail.com">tluozhenwei@gmail.com</a>&gt;<br>
To: <a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a><br>
Subject: [cctbxbb] Passing array between python and C++<br>
Message-ID: &lt;<a href="mailto:90518A19-AC1B-493B-8B27-79D31EDDF055@gmail.com">90518A19-AC1B-493B-8B27-79D31EDDF055@gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=us-ascii<br>
<br>
Hello Everyone,<br>
<br>
        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>
<br>
It gave me an error:<br>
<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>
<br>
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>


<br>
Thank you very much! Any help will be greatly appreciated.<br>
<br>
Sincerely,<br>
Zhenwei Luo<br>
Rice University<br>
<br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Sat, 7 Dec 2013 20:45:10 -0800<br>
From: Nathaniel Echols &lt;<a href="mailto:nechols@lbl.gov">nechols@lbl.gov</a>&gt;<br>
To: cctbx mailing list &lt;<a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a>&gt;<br>
Subject: Re: [cctbxbb] Passing array between python and C++<br>
Message-ID:<br>
        &lt;CALeAa1MOL1wbW5Vb=M=<a href="mailto:jXsnGTaCBQNJjcOzDwMhM27x5PP%2BXNA@mail.gmail.com">jXsnGTaCBQNJjcOzDwMhM27x5PP+XNA@mail.gmail.com</a>&gt;<br>
Content-Type: text/plain; charset=&quot;iso-8859-1&quot;<br>
<br>
On Sat, Dec 7, 2013 at 8:25 PM, Zhenwei Luo &lt;<a href="mailto:tluozhenwei@gmail.com">tluozhenwei@gmail.com</a>&gt; wrote:<br>
<br>
&gt;         I am writing a refinement program using the cctbx. I have<br>
&gt; encountered with a problem when I wanted to pass an array between c++ and<br>
&gt; python. The type of array I used in my c++ source file is<br>
&gt; af::shared&lt;af::shared&lt;vec3&gt; &gt;, I would like to pass it into my python<br>
&gt; script, thus I could do some other operations to this array.<br>
&gt; I wrote a method in my class to return this array.<br>
&gt;<br>
&gt;  af::shared&lt;af::shared&lt;vec3&lt;double&gt; &gt; return_modes( ) { return modes; }<br>
&gt;<br>
&gt; I wrote another method in the *_ext file to wrap this method to make it<br>
&gt; callable from python.<br>
&gt;<br>
&gt; .def(&quot;return_modes&quot;, &amp;nm_init::return_modes)<br>
&gt;<br>
&gt; But when I use it in python,<br>
&gt; eigenvector = nm_init_manager.return_modes()<br>
&gt; It gave me an error:<br>
&gt; TypeError: No to_python (by-value) converter found for c++ type:<br>
&gt; scitbx::af::shared&lt;scitbx::af::shared&lt;scitbx::vec3&lt;double&gt; &gt; &gt;<br>
&gt;<br>
<br>
What that error means is that boost.python doesn&#39;t know how to present this<br>
new type to Python.  For the data structures that we pass back and forth,<br>
we have to explicitly provide wrappers for them - including new<br>
instantiations of scitbx::array_family templates.<br>
<br>
What I want to realize is just creating an two dimensional array using vec3<br>
&gt; as its element. I can also using the select method  in this array to select<br>
&gt; some elements from its column, just like in the af::shared&lt;vec3&lt;double&gt; &gt;<br>
&gt; array. Namely, the column of this array should have some same properties<br>
&gt; like af::shared&lt;vec3&lt;double&gt; &gt;. Can anyone help me figure out what I should<br>
&gt; do?<br>
&gt;<br>
<br>
In general the scitbx::array_family templates aren&#39;t really intended to<br>
every be multidimensional; for inherently 2D and 3D data types like images<br>
and maps, we use flex.grid to provide a multi-dimensional accessor on top<br>
of the 1D array.  The grid may not be the most appropriate in your case but<br>
if I&#39;m making the correct assumptions about the data you&#39;re trying to pass<br>
back and forth, I think it might be easiest to simply define a custom class<br>
that contains a std::vector of af::shared&lt;vec3&gt; arrays, and add an index<br>
parameter to the return_modes method, which would be modified to return<br>
only a single array of modes at a time.  You can also do things like<br>
wrapping a method as __getitem__ with boost.python, which would mimic a 2D<br>
array.  (I can probably dig up/cook up some code examples tomorrow if this<br>
is unclear, since it was certainly not intuitive to me when I started<br>
working with CCTBX and it would be nice to have documentation for the<br>
future.)<br>
<br>
-Nat<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: &lt;<a href="http://phenix-online.org/pipermail/cctbxbb/attachments/20131207/91a774e3/attachment.html" target="_blank">http://phenix-online.org/pipermail/cctbxbb/attachments/20131207/91a774e3/attachment.html</a>&gt;<br>


<br>
------------------------------<br>
<br>
_______________________________________________<br>
cctbxbb mailing list<br>
<a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a><br>
<a href="http://phenix-online.org/mailman/listinfo/cctbxbb" target="_blank">http://phenix-online.org/mailman/listinfo/cctbxbb</a><br>
<br>
<br>
End of cctbxbb Digest, Vol 59, Issue 1<br>
**************************************<br>
</blockquote></div><br></div>