Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upBindings for views (or xstrided_views) #130
Comments
|
With some of the recent additions this is definitly possible (at least for "easy" views that don't use the new islice), and for the strided view. |
|
I am interested in working on this. I wonder if there's a pointer (like a file or a PR) to the "easy" views that don't use the new islice? My project needs to share large buffers among C++ and Python. It seems that, without the requested feature, xtensor-python always copies the buffer when an array is passed across the wrapper. c = xt.C()
self.assertEqual([0.]*10, c.array.tolist())
# use __setitem__ implemented in C++ to set the element.
c[0] = 3
self.assertEqual([3.] + [0.]*9, c.array.tolist())
# c.array returns a copy while I want a view.
arr = c.array
arr[1] = 1
# FIXME: this assertion fails
self.assertEqual([3., 1.] + [0.]*8, c.array.tolist()) |
|
The view mentioned here is the strided view. The idea would be to have a similar class in |
I was trying to get an array view from cpp and call a python function back with it.
After some help, I managed to do it by converting the view to a
xt::pytensorbefore proceeding with the Python call (See code below).It would be nice to have some way to pass the view directly to the python function, instead of having to convert them. It seems that it is not possible to make bindings for
xt::viewdirectly, though. I'll leave the original discussion here for reference: