Skip to content

Bindings for views (or xstrided_views) #130

Open
@tarcisiofischer

Description

@tarcisiofischer

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::pytensor before proceeding with the Python call (See code below).

void cpp_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);
}
def test_view():
    def py_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 for xt::view directly, though. I'll leave the original discussion here for reference:

Tarcísio Fischer @tarcisiofischer 14:49
Do you know if there'll be bindings for the xt::view anytime soon?

Johan Mabille @JohanMabille 14:50
the thing is numpy view and xtensor views are not exactly the same so we cannot bind view directly

Sylvain Corlay @SylvainCorlay 14:50
Not as a numpy array, but there is some hope for strided views on pyarrays / pytensor.

Johan Mabille @JohanMabille 14:50
we have xstrided_views that works like numpy views, we can make bindings for them

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions