<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's not very convenient for my program. It'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"><<a href="mailto:cctbxbb-request@phenix-online.org" target="_blank">cctbxbb-request@phenix-online.org</a>></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 'help' 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 "Re: Contents of cctbxbb digest..."<br>
<br>
<br>
Today'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 <<a href="mailto:tluozhenwei@gmail.com">tluozhenwei@gmail.com</a>><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: <<a href="mailto:90518A19-AC1B-493B-8B27-79D31EDDF055@gmail.com">90518A19-AC1B-493B-8B27-79D31EDDF055@gmail.com</a>><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<af::shared<vec3> >, 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<af::shared<vec3<double> > 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("return_modes", &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<scitbx::af::shared<scitbx::vec3<double> > ><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<vec3<double> > array. Namely, the column of this array should have some same properties like af::shared<vec3<double> >. 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 <<a href="mailto:nechols@lbl.gov">nechols@lbl.gov</a>><br>
To: cctbx mailing list <<a href="mailto:cctbxbb@phenix-online.org">cctbxbb@phenix-online.org</a>><br>
Subject: Re: [cctbxbb] Passing array between python and C++<br>
Message-ID:<br>
<CALeAa1MOL1wbW5Vb=M=<a href="mailto:jXsnGTaCBQNJjcOzDwMhM27x5PP%2BXNA@mail.gmail.com">jXsnGTaCBQNJjcOzDwMhM27x5PP+XNA@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
On Sat, Dec 7, 2013 at 8:25 PM, Zhenwei Luo <<a href="mailto:tluozhenwei@gmail.com">tluozhenwei@gmail.com</a>> wrote:<br>
<br>
> I am writing a refinement program using the cctbx. I have<br>
> encountered with a problem when I wanted to pass an array between c++ and<br>
> python. The type of array I used in my c++ source file is<br>
> af::shared<af::shared<vec3> >, I would like to pass it into my python<br>
> 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<af::shared<vec3<double> > return_modes( ) { return modes; }<br>
><br>
> I wrote another method in the *_ext file to wrap this method to make it<br>
> callable from python.<br>
><br>
> .def("return_modes", &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:<br>
> scitbx::af::shared<scitbx::af::shared<scitbx::vec3<double> > ><br>
><br>
<br>
What that error means is that boost.python doesn'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>
> as its element. I can also using the select method in this array to select<br>
> some elements from its column, just like in the af::shared<vec3<double> ><br>
> array. Namely, the column of this array should have some same properties<br>
> like af::shared<vec3<double> >. Can anyone help me figure out what I should<br>
> do?<br>
><br>
<br>
In general the scitbx::array_family templates aren'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'm making the correct assumptions about the data you'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<vec3> 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: <<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>><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>