diff --git a/include/libpy/ndarray_view.h b/include/libpy/ndarray_view.h index a03eeef0..2fae36e4 100644 --- a/include/libpy/ndarray_view.h +++ b/include/libpy/ndarray_view.h @@ -42,9 +42,11 @@ 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}}; + return {static_cast(start), + {static_cast(size)}, + {static_cast(stride)}}; } } // namespace detail @@ -66,7 +68,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 +81,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 +122,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 +169,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 +230,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 +593,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 +699,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 +748,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 +765,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 +829,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 +1412,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());