mirror of
https://github.com/pybind/pybind11.git
synced 2026-06-06 07:51:47 +00:00
feat: vectorize functions with void return type (#1969)
* Allow function/functor passed to py::vectorize to return void * Stealing @sizmailov's test and fixing unused argument warning * Add missing std::move() RVO doesn't work here because function return type is different from actual returned type * remove extra EOL * docs: add a few details * chore: pre-commit autoupdate * Remove array_iterator, array_begin, and array_end (in detail namespace) Co-authored-by: Sergei Izmailov <sergei.a.izmailov@gmail.com> Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -50,7 +50,9 @@ TEST_SUBMODULE(numpy_vectorize, m) {
|
||||
NonPODClass(int v) : value{v} {}
|
||||
int value;
|
||||
};
|
||||
py::class_<NonPODClass>(m, "NonPODClass").def(py::init<int>());
|
||||
py::class_<NonPODClass>(m, "NonPODClass")
|
||||
.def(py::init<int>())
|
||||
.def_readwrite("value", &NonPODClass::value);
|
||||
m.def("vec_passthrough", py::vectorize(
|
||||
[](double *a, double b, py::array_t<double> c, const int &d, int &e, NonPODClass f, const double g) {
|
||||
return *a + b + c.at(0) + d + e + f.value + g;
|
||||
@@ -86,4 +88,6 @@ TEST_SUBMODULE(numpy_vectorize, m) {
|
||||
std::array<py::buffer_info, 3> buffers {{ arg1.request(), arg2.request(), arg3.request() }};
|
||||
return py::detail::broadcast(buffers, ndim, shape);
|
||||
});
|
||||
|
||||
m.def("add_to", py::vectorize([](NonPODClass& x, int a) { x.value += a; }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user