- Notifications
You must be signed in to change notification settings - Fork63
Open
Labels
Description
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 axt::pytensor
before proceeding with the Python call (See code below).
voidcpp_f(xt::pytensor<double,2> my_arr, py::object py_f) {auto v = xt::pytensor<double,1>(xt::view(my_arr,0,xt::all()));py_f(v);}
deftest_view():defpy_f(v):print(v)cpp_f(np.array([ [1,2,3], [4,5,6], ]),py_f)
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 forxt::view
directly, though. I'll leave the original discussion here for reference:
Tarcísio Fischer @tarcisiofischer 14:49Do you know if there'll be bindings for the xt::view anytime soon?Johan Mabille @JohanMabille 14:50the thing is numpy view and xtensor views are not exactly the same so we cannot bind view directlySylvain Corlay @SylvainCorlay 14:50Not as a numpy array, but there is some hope for strided views on pyarrays / pytensor.Johan Mabille @JohanMabille 14:50we have xstrided_views that works like numpy views, we can make bindings for them