wjakob / nanobind

nanobind: tiny and efficient C++/Python bindings
BSD 3-Clause "New" or "Revised" License
2.14k stars 161 forks source link

ndarray import from buffer protocol requires integer stride. #489

Closed hpkfft closed 3 months ago

hpkfft commented 3 months ago

In the numpy buffer protocol, strides are measured in bytes. If a stride (in any dimension) is not an integer multiple of itemsize, then the stride cannot be correctly converted to number of elements.

With this PR, a function taking such an nb::ndarray argument will raise a TypeError exception.

wjakob commented 3 months ago

This looks great, thank you! No worries about the failing tests.