diff --git a/include/xtensor-python/pycontainer.hpp b/include/xtensor-python/pycontainer.hpp index 7b9a90e..deeefb2 100644 --- a/include/xtensor-python/pycontainer.hpp +++ b/include/xtensor-python/pycontainer.hpp @@ -93,6 +93,7 @@ namespace xt void reshape(S&& shape, layout_type layout = base_type::static_layout); layout_type layout() const; + bool is_contiguous() const noexcept; using base_type::operator(); using base_type::operator[]; @@ -442,6 +443,27 @@ namespace xt } } + /** + * Return whether or not the container uses contiguous buffer + * @return Boolean for contiguous buffer + */ + template + inline bool pycontainer::is_contiguous() const noexcept + { + if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_C_CONTIGUOUS)) + { + return 1 == this->strides().back(); + } + else if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_F_CONTIGUOUS)) + { + return 1 == this->strides().front(); + } + else + { + return false; + } + } + /** * Import the numpy Python module. */