Skip to content

Commit a956ad8

Browse files
committed
Make contiguous check for pyarray more robust
For row-major (c contiguous), make sure the last stride is unity. For colunm-major (fortran contiguous), make sure the first stride is unity.
1 parent 7033020 commit a956ad8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/xtensor-python/pycontainer.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,18 @@ namespace xt
450450
template <class D>
451451
inline bool pycontainer<D>::is_contiguous() const noexcept
452452
{
453-
return layout_type::dynamic != layout();
453+
if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_C_CONTIGUOUS))
454+
{
455+
return 1 == this->strides().back();
456+
}
457+
else if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_F_CONTIGUOUS))
458+
{
459+
return 1 == this->strides().front();
460+
}
461+
else
462+
{
463+
return false;
464+
}
454465
}
455466

456467
/**

0 commit comments

Comments
 (0)