diff --git a/include/xtensor-python/pyarray.hpp b/include/xtensor-python/pyarray.hpp index 03e803d..8979fcf 100644 --- a/include/xtensor-python/pyarray.hpp +++ b/include/xtensor-python/pyarray.hpp @@ -172,12 +172,12 @@ namespace xt void init_array(const shape_type& shape, const strides_type& strides); void init_from_python(); - const inner_shape_type& shape_impl() const; - const inner_strides_type& strides_impl() const; - const inner_backstrides_type& backstrides_impl() const; + const inner_shape_type& shape_impl() const noexcept; + const inner_strides_type& strides_impl() const noexcept; + const inner_backstrides_type& backstrides_impl() const noexcept; - container_type& data_impl(); - const container_type& data_impl() const; + container_type& data_impl() noexcept; + const container_type& data_impl() const noexcept; friend class xcontainer>; }; @@ -383,19 +383,19 @@ namespace xt } template - inline auto pyarray::shape_impl() const -> const inner_shape_type& + inline auto pyarray::shape_impl() const noexcept -> const inner_shape_type& { return m_shape; } template - inline auto pyarray::strides_impl() const -> const inner_strides_type& + inline auto pyarray::strides_impl() const noexcept -> const inner_strides_type& { return m_strides; } template - inline auto pyarray::backstrides_impl() const -> const inner_backstrides_type& + inline auto pyarray::backstrides_impl() const noexcept -> const inner_backstrides_type& { // The pyarray object may be copied, invalidating m_backstrides. Building // it each time it is needed avoids tricky bugs. @@ -404,13 +404,13 @@ namespace xt } template - inline auto pyarray::data_impl() -> container_type& + inline auto pyarray::data_impl() noexcept -> container_type& { return m_data; } template - inline auto pyarray::data_impl() const -> const container_type& + inline auto pyarray::data_impl() const noexcept -> const container_type& { return m_data; } diff --git a/include/xtensor-python/pytensor.hpp b/include/xtensor-python/pytensor.hpp index 27971b9..a3f5383 100644 --- a/include/xtensor-python/pytensor.hpp +++ b/include/xtensor-python/pytensor.hpp @@ -140,7 +140,6 @@ namespace xt void init_tensor(const shape_type& shape, const strides_type& strides); void init_from_python(); - void compute_backstrides(); inner_shape_type& shape_impl() noexcept; const inner_shape_type& shape_impl() const noexcept; @@ -281,7 +280,7 @@ namespace xt this->m_ptr = tmp.release().ptr(); m_shape = shape; m_strides = strides; - compute_backstrides(); + adapt_strides(m_shape, m_strides, m_backstrides); m_data = container_type(reinterpret_cast(PyArray_DATA(this->python_array())), static_cast(PyArray_SIZE(this->python_array()))); } @@ -297,20 +296,11 @@ namespace xt std::copy(PyArray_DIMS(this->python_array()), PyArray_DIMS(this->python_array()) + N, m_shape.begin()); std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(), [](auto v) { return v / sizeof(T); }); - compute_backstrides(); + adapt_strides(m_shape, m_strides, m_backstrides); m_data = container_type(reinterpret_cast(PyArray_DATA(this->python_array())), static_cast(PyArray_SIZE(this->python_array()))); } - template - inline void pytensor::compute_backstrides() - { - for (size_type i = 0; i < m_shape.size(); ++i) - { - m_backstrides[i] = m_strides[i] * (m_shape[i] - 1); - } - } - template inline auto pytensor::shape_impl() noexcept -> inner_shape_type& {