pybind/pybind11

Not clear how to expose existing C++ vector as numpy array

Open

#1.042 aberto em 30 de ago. de 2017

Ver no GitHub
 (37 comments) (27 reactions) (0 assignees)C++ (2.005 forks)batch import
enhancementhelp wanted

Métricas do repositório

Stars
 (14.677 stars)
Métricas de merge de PR
 (Mesclagem média 5d 2h) (10 fundiu PRs em 30d)

Description

This is a question of documentation rather than an issue. I can't find any example of the following very common scenario:

std::vector<int> some_func();
...
// We want to expose returned std::vector as a numpy array without copying
m.def("some_func", []() -> py::array {
   auto data = some_func();
   // What to do with data?? Map it with Eigen (then return what?), wrap somehow with py::buffer (how?)
})

I don't know the answer. It would be very nice to have this explained in docs since this scenario if rather common.

Guia do colaborador