Skip to content

Commit

Permalink
BUG: Fix alignment errors due to relaxed stride checking (#14893)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbell10 committed Oct 20, 2021
1 parent b648161 commit cd1c680
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scipy/spatial/src/distance_pybind.cpp
Expand Up @@ -225,6 +225,13 @@ ArrayDescriptor get_descriptor(const py::array& arr) {
const auto arr_strides = arr.strides();
desc.strides.assign(arr_strides, arr_strides + ndim);
for (intptr_t i = 0; i < ndim; ++i) {
if (arr_shape[i] <= 1) {
// Under NumPy's relaxed stride checking, dimensions with
// 1 or fewer elements are ignored.
desc.strides[i] = 0;
continue;
}

if (desc.strides[i] % desc.element_size != 0) {
std::stringstream msg;
msg << "Arrays must be aligned to element size, but found stride of ";
Expand Down

0 comments on commit cd1c680

Please sign in to comment.