From 9077a9daee61da7aa4d74fe145446892d3a80b52 Mon Sep 17 00:00:00 2001 From: Gerry Manoim Date: Fri, 10 Jul 2020 13:56:38 -0400 Subject: [PATCH 1/3] ENH: strides is now a std::ptrdiff_t --- include/libpy/ndarray_view.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/libpy/ndarray_view.h b/include/libpy/ndarray_view.h index a03eeef0..d410752c 100644 --- a/include/libpy/ndarray_view.h +++ b/include/libpy/ndarray_view.h @@ -42,7 +42,7 @@ slice_impl(const T& view, std::int64_t start, std::int64_t stop, std::int64_t st } std::int64_t size = (low >= high) ? 0 : (high - low - 1) / adj_step + 1; - std::int64_t stride = view.strides()[0] * step; + std::ptrdiff_t stride = view.strides()[0] * step; return {static_cast(start), {static_cast(size)}, {stride}}; } @@ -66,7 +66,7 @@ class ndarray_view { friend class ndarray_view; std::array m_shape; - std::array m_strides; + std::array m_strides; buffer_type m_buffer; std::ptrdiff_t pos_to_index(const std::array& pos) const { @@ -79,7 +79,7 @@ class ndarray_view { ndarray_view(buffer_type buffer, const std::array shape, - const std::array& strides) + const std::array& strides) : m_shape(shape), m_strides(strides), m_buffer(buffer) {} public: @@ -120,7 +120,7 @@ class ndarray_view { } std::array shape; - std::array strides; + std::array strides; for (int ix = 0; ix < buf->ndim; ++ix) { shape[ix] = static_cast(buf->shape[ix]); strides[ix] = static_cast(buf->strides[ix]); @@ -167,7 +167,7 @@ class ndarray_view { */ ndarray_view(T* buffer, const std::array shape, - const std::array& strides) + const std::array& strides) : ndarray_view(reinterpret_cast(buffer), shape, strides) {} /** Access the element at the given index with bounds checking. @@ -228,7 +228,7 @@ class ndarray_view { /** The number of bytes to go from one element to the next. */ - const std::array& strides() const { + const std::array& strides() const { return m_strides; } @@ -591,7 +591,7 @@ class any_ref_ndarray_view { friend class any_ref_ndarray_view; std::array m_shape; - std::array m_strides; + std::array m_strides; buffer_type m_buffer; any_vtable m_vtable; @@ -697,10 +697,10 @@ class any_ref_ndarray_view { } std::array shape; - std::array strides; + std::array strides; for (int ix = 0; ix < buf->ndim; ++ix) { shape[ix] = static_cast(buf->shape[ix]); - strides[ix] = static_cast(buf->strides[ix]); + strides[ix] = static_cast(buf->strides[ix]); } return {ndarray_view{static_cast(buf->buf), @@ -746,7 +746,7 @@ class any_ref_ndarray_view { any_ref_ndarray_view(buffer_type buffer, const std::array shape, - const std::array& strides, + const std::array& strides, const py::any_vtable& vtable) : m_shape(shape), m_strides(strides), m_buffer(buffer), m_vtable(vtable) {} @@ -763,7 +763,7 @@ class any_ref_ndarray_view { template any_ref_ndarray_view(U* buffer, const std::array shape, - const std::array& strides) + const std::array& strides) : any_ref_ndarray_view(reinterpret_cast(buffer), shape, strides, @@ -827,7 +827,7 @@ class any_ref_ndarray_view { /** The number of bytes to go from one element to the next. */ - const std::array& strides() const { + const std::array& strides() const { return m_strides; } @@ -1410,7 +1410,7 @@ struct from_object> { } std::array shape{0}; - std::array strides{0}; + std::array strides{0}; std::copy_n(PyArray_SHAPE(array), ndim, shape.begin()); std::copy_n(PyArray_STRIDES(array), ndim, strides.begin()); From 49dc383ed6aaa908286b8d10a73f2dedf291b2e9 Mon Sep 17 00:00:00 2001 From: Gerry Manoim Date: Wed, 15 Jul 2020 13:48:41 -0400 Subject: [PATCH 2/3] static cast? --- include/libpy/ndarray_view.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/libpy/ndarray_view.h b/include/libpy/ndarray_view.h index d410752c..843ababc 100644 --- a/include/libpy/ndarray_view.h +++ b/include/libpy/ndarray_view.h @@ -44,8 +44,9 @@ slice_impl(const T& view, std::int64_t start, std::int64_t stop, std::int64_t st std::int64_t size = (low >= high) ? 0 : (high - low - 1) / adj_step + 1; std::ptrdiff_t stride = view.strides()[0] * step; - return {static_cast(start), {static_cast(size)}, {stride}}; -} + return {static_cast(start), + {static_cast(size)}, + {static_cast(stride)}};} } // namespace detail /** A struct to wrap an array of type T whose shape is not known until runtime. From 34bc8945e56cb3b3a9484f800323d948eca7d1ed Mon Sep 17 00:00:00 2001 From: Gerry Manoim Date: Wed, 15 Jul 2020 13:53:52 -0400 Subject: [PATCH 3/3] fmt --- include/libpy/ndarray_view.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/libpy/ndarray_view.h b/include/libpy/ndarray_view.h index 843ababc..2fae36e4 100644 --- a/include/libpy/ndarray_view.h +++ b/include/libpy/ndarray_view.h @@ -46,7 +46,8 @@ slice_impl(const T& view, std::int64_t start, std::int64_t stop, std::int64_t st return {static_cast(start), {static_cast(size)}, - {static_cast(stride)}};} + {static_cast(stride)}}; +} } // namespace detail /** A struct to wrap an array of type T whose shape is not known until runtime.