xtensor-python icon indicating copy to clipboard operation
xtensor-python copied to clipboard

dtype gets implicitly converted, and buffer is copied

Open wolfv opened this issue 6 years ago • 2 comments

When we have a function taking a pyarray but pass in a numpy array of integers, the numpy array is implicitly converted to a pyarray of doubles (but this creates a copy of the buffer).

We should think about emitting a warning in this case, or make the warning user modifiable. Or at least clearly document it.

wolfv avatar Dec 14 '17 16:12 wolfv

Actually in pybind11 there is a compile-time option like so:

void f(py::array_t<double, py::array::c_style | py::array::forcecast> array);

To signify if that array should be casted or not. Maybe we could use that, or something similar?

wolfv avatar Jun 21 '18 06:06 wolfv

Is this a similar issue to the following:

Suppose we have a function

void foo(xt::pytensor<int, 1>& arg)

that changes arg in place. Then currently the call to the function with the wrong numpy.dtype does not result in any error, but does not change the desired object either because of an implicit type conversion. The questions are:

  1. What can be done to switch off the implicit conversion in specific cases?
  2. How can a function be overloaded for all relevant NumPy types?

cc @JohanMabille

tdegeus avatar Nov 28 '23 09:11 tdegeus