From 70330207524d5f26eee60259a3025356b8c1f614 Mon Sep 17 00:00:00 2001 From: Yung-Yu Chen Date: Fri, 4 Oct 2019 11:02:27 +0800 Subject: [PATCH 1/2] Compatibility for upstream xtensor change The upstream change broke the build: https://github.com/QuantStack/xtensor/commit/da7de15be73c396bc9ffb31fe8c630938c57ffe8 Add pycontainer::is_contiguous to make xtensor happy. --- include/xtensor-python/pycontainer.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/xtensor-python/pycontainer.hpp b/include/xtensor-python/pycontainer.hpp index 7b9a90e..e92bbec 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,16 @@ namespace xt } } + /** + * Return whether or not the container uses contiguous buffer + * @return Boolean for contiguous buffer + */ + template + inline bool pycontainer::is_contiguous() const noexcept + { + return layout_type::dynamic != layout(); + } + /** * Import the numpy Python module. */ From a956ad80005dac3e68aad6963f6ddfc9317f917e Mon Sep 17 00:00:00 2001 From: Yung-Yu Chen Date: Thu, 10 Oct 2019 00:13:28 +0800 Subject: [PATCH 2/2] 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. --- include/xtensor-python/pycontainer.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/xtensor-python/pycontainer.hpp b/include/xtensor-python/pycontainer.hpp index e92bbec..deeefb2 100644 --- a/include/xtensor-python/pycontainer.hpp +++ b/include/xtensor-python/pycontainer.hpp @@ -450,7 +450,18 @@ namespace xt template inline bool pycontainer::is_contiguous() const noexcept { - return layout_type::dynamic != layout(); + 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; + } } /**