add stride-aware constructor for NDView

This commit is contained in:
2025-10-13 20:06:16 +02:00
parent c0ee17275e
commit e290c8f820

View File

@@ -93,6 +93,12 @@ class NDView : public ArrayExpr<NDView<T, Ndim>, Ndim> {
: buffer_(buffer), strides_(c_strides<Ndim>(shape)), shape_(shape), : buffer_(buffer), strides_(c_strides<Ndim>(shape)), shape_(shape),
size_(std::accumulate(std::begin(shape), std::end(shape), 1, size_(std::accumulate(std::begin(shape), std::end(shape), 1,
std::multiplies<>())) {} std::multiplies<>())) {}
// stride-aware constructor
NDView(T* buffer, std::array<ssize_t, Ndim> shape, std::array<ssize_t, Ndim> strides)
: buffer_(buffer), shape_(shape), strides_(strides),
size_(std::accumulate(std::begin(shape), std::end(shape), 1,
std::multiplies<>())) {}
template <typename... Ix> template <typename... Ix>
std::enable_if_t<sizeof...(Ix) == Ndim, T &> operator()(Ix... index) { std::enable_if_t<sizeof...(Ix) == Ndim, T &> operator()(Ix... index) {