Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix alignment errors due to relaxed stride checking #14893

Merged
merged 1 commit into from Oct 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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