teaching xdress about recursive array structure

16 views
Skip to first unread message

Geoffrey Irving

unread,
Aug 5, 2014, 3:00:40 PM8/5/14
to xdress
Our current C++/Python interaction layer has a bunch of logic for
converting nested array, vector, and matrix types in C++ into numpy
arrays in Python. For example, we have classes

Vector<T,d> - static size vectors of T
Matrix<T,m,n> - static size m by n matrices of T
Array<T,d> - rectangular d-dimensional arrays of d

and a type like

Array<Vector<Matrix<T,3,2>,5>,4>

would turn into 7D numpy array with shape (a,b,c,d,5,3,2).

I am a bit lost as to how to cleanly expose this structure to xdress.
At first I thought I could just reuse our existing
from_python/to_python C++ functions and teach xdress about them via
register_class, but that doesn't work if the underling "scalar" type
is something only xdress knows how to convert.

I imagine this is somewhat similar to the stl layer, the main
difference being that Array can share memory with other instances and
therefore be convert to and from numpy arrays without copying.

Geoffrey

Anthony Scopatz

unread,
Aug 14, 2014, 8:30:51 PM8/14/14
to Geoffrey Irving, xdress
Hi Geoffrey, 

Sorry for taking so long to get back to you. I believe that you don't need to replicate the STL layer.  The STL wrapping layer is there such that the standard library containers inherit from the corresponding collections abstract base class and expose a Pythonic API. That is, it makes it so std::set<T> is a collections.MutableSet. Operations and methods thus look like the Python version rather than the C++ version.

If you just want the Array / Matrix / Vectors to be exposed as solely as numpy views than you can (should) do this through the to / from functions much like the std::vector<T> does. If you want these classes to retain their API but be viewable as numpy arrays, then I think it would be best to have xdress generate a dtype for them. 

I guess I am still a little unclear as to the exact use case you have. Can you point us at some code that is failing?

Be Well
Anthony



Geoffrey

--
You received this message because you are subscribed to the Google Groups "xdress" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/xdress/CAJ1ofpfhRqOiAtxfWaO7iBTHm%3DxPP%3DanEzB7xO%3DWdYV_q4hFJw%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages