pybind/pybind11

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

Open

#1,042 建立於 2017年8月30日

在 GitHub 查看
 (37 留言) (27 反應) (0 負責人)C++ (2,005 fork)batch import
enhancementhelp wanted

倉庫指標

Star
 (14,677 star)
PR 合併指標
 (平均合併 5天 2小時) (30 天內合併 10 個 PR)

描述

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.

貢獻者指南