ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
Re: [C++-sig] How to call reshape((M,N),order='F') ?
by Sebastian Walter other posts by this author
Oct 28 2009 12:46PM messages near this date
[C++-sig] How to call reshape((M,N),order='F') ? | Re: [C++-sig] How to call reshape((M,N),order='F') ?
>  Hello to everyone.
> 
>  I have this problem.
> 
>  Assume I'm building a to-Python converter for a 3x2 matrix type,
>  FORTRAN storage (these are not the real dimensions of my problem, but
>  I give these numbers only to simplify the discussion).
> 
>  Into the "convert" C++ method, first, I build a list with all the
>  matrix elements (lout);
>  then, I instantiate a boost::python::numeric::array in this way (note:
>  I had previously used
>  set_module_and_type("numpy","ndarray"), for using the NumPy's array):
> 
>  boost::python::numeric::array   v(lout)
> 
>  Finally, I'd like to call "reshape" on this array, in this way
> 
>  v.attr("reshape")(make_tuple(3,2),"F");

don't know the answer to your question, but you could do the following:

set the strides of the underlying PyArrayObject manually to match column
major format, i.e.
PyArrayObject  *v_array_obj = reinterpret_cast<PyArrayObject*>  ( v.ptr() );
v_array_obj-> strides[0] = sizeof(double);
v_array_obj-> strides[1] = 3 * sizeof(double);

hope that helps,

Sebastian


> 
>  But it does not work. It builds, but, on runtime, I obtain the error:
> 
>  Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>  TypeError: an integer is required
> 
>  I tried to build and re-shape a matrix entirely from Python and I
>  discovered that, when using reshape,
>  you are forced to give the second parameter as
> 
>  order = 'C' or 'F'
> 
>  Now the question is: is it possible to specify a named parameter from
>  the C++ code ?
>  If the answer is "yes", how ?
> 
>  Thank you in advance,
>  Michele
> 
>  --
>  Michele De Stefano
>  http://www.linkedin.com/in/micdestefano
>  _______________________________________________
>  Cplusplus-sig mailing list
>  Cplusplus-sig@[...].org
>  http://mail.python.org/mailman/listinfo/cplusplus-sig
> 


-- 
Sebastian Walter

Institut fuer Mathematik, Humboldt-Universitaet    Tel: +49 (30) 2093-5869
Rudower Chaussee 25, Adlershof, Berlin             Fax: +49 (30) 2093-5859
Post: Unter den Linden 6, D-10099 Berlin         Email: 
walter@[...].de
WWW: http://www.mathematik.hu-berlin.de/~walter

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@[...].org
http://mail.python.org/mailman/listinfo/cplusplus-sig
Thread:
Michele De Stefano
Sebastian Walter
Michele De Stefano

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved