You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems noconvert is not supported? I tried adding noconvert to my (now classic) summer.cc:
#include <numpy/arrayobject.h>
#include "pybind11/numpy.h" // complex
#include "pybind11/pybind11.h"
#include "pybind11/operators.h"
#include "numpy/arrayobject.h"
//#include "ndarray/pybind11.h"
#include "xtensor/xtensor.hpp"
#include "xtensor/xcontainer.hpp"
#include "xtensor-python/pyarray.hpp"
#include <complex>
namespace py = pybind11;
PYBIND11_PLUGIN (summer) {
if (_import_array() < 0) {
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
return nullptr;
}
py::module m("summer", "pybind11 example plugin");
// m.def("sum", [](xt::pyarray<double> const& x) {
// xt::xtensor<double, 1> tmp(x);
// double sum = 0;
// for (auto e : tmp)
// sum += e;
// return sum;
// });
m.def("sum", [](xt::pyarray<std::complex<double>> const& x) {
std::complex<double> sum = 0;
for (auto e : x)
sum += e;
return sum;
},
py::arg("inp").noconvert()
);
m.def("sum", [](xt::pyarray<double> const& x) {
double sum = 0;
for (auto e : x)
sum += e;
return sum;
},
py::arg("inp").noconvert()
);
return m.ptr();
}
It seems to have no effect. If I reverse the order of the defs (double is 1st), then when passing a complex array I get the numpy warning of discarding imag part. If I use the order above, the time for processing float array is much more than for complex array, suggesting there is conversion.
It seems noconvert is not supported? I tried adding noconvert to my (now classic) summer.cc:
It seems to have no effect. If I reverse the order of the defs (double is 1st), then when passing a complex array I get the numpy warning of discarding imag part. If I use the order above, the time for processing float array is much more than for complex array, suggesting there is conversion.