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
(cherry picked from commit cd1c680)
  • Loading branch information
peterbell10 authored and rgommers committed Oct 29, 2021
1 parent b4fb2ec commit cd2e9dc
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) {
throw std::runtime_error("Arrays must be aligned");
}
Expand Down

0 comments on commit cd2e9dc

Please sign in to comment.