6 #ifndef ECHELON_HDF5_ARRAY_SLICE_HPP 7 #define ECHELON_HDF5_ARRAY_SLICE_HPP 9 #include <echelon/hdf5/range.hpp> 10 #include <echelon/hdf5/container_adaption.hpp> 24 array_slice(T* data_, std::vector<hsize_t> original_shape_, std::vector<hsize_t> offset_,
25 std::vector<hsize_t> shape_, std::vector<hsize_t> stride_)
26 : data_(std::move(data_)), original_shape_(std::move(original_shape_)),
27 offset_(std::move(offset_)), shape_(std::move(shape_)), stride_(std::move(stride_))
31 template <
typename... Indices>
32 T operator()(Indices... indices)
const 34 std::vector<hsize_t> indices_({
static_cast<hsize_t
>(indices)...});
36 hsize_t linear_index = 0;
38 for (std::size_t i = indices_.size(); i-- > 0;)
41 linear_index * original_shape_[i] + (offset_[i] + indices_[i] * stride_[i]);
44 return data_[linear_index];
52 const std::vector<hsize_t>& original_shape()
const 54 return original_shape_;
57 const std::vector<hsize_t>& offset()
const 62 const std::vector<hsize_t>& shape()
const 67 const std::vector<hsize_t>& stride()
const 74 std::vector<hsize_t> original_shape_;
75 std::vector<hsize_t> offset_;
76 std::vector<hsize_t> shape_;
77 std::vector<hsize_t> stride_;
88 template <
typename C,
typename... Args>
89 array_slice<typename container_trait<C>::value_type>
make_slice(C&& container, Args... args)
91 static_assert(is_container<C>(),
"C does not fulfill the Container requirements.");
93 using value_type =
typename container_trait<C>::value_type;
95 std::vector<hsize_t> shape_;
97 auto shape = echelon::hdf5::shape_adl(container);
99 for (
auto extent : shape)
101 shape_.push_back(extent);
104 std::vector<totally_bound_range_t> slice_boundaries;
106 detail::calculate_slice_boundaries<0, Args...>::eval(shape_, slice_boundaries, args...);
108 std::vector<hsize_t> offset;
109 std::vector<hsize_t> slice_shape;
110 std::vector<hsize_t> stride;
112 for (
auto bounds : slice_boundaries)
114 auto base = bounds.base();
116 offset.push_back(base);
117 slice_shape.push_back(bounds.bound() - base);
118 stride.push_back(bounds.stride());
121 return array_slice<value_type>(echelon::hdf5::data_adl(container), std::move(shape_),
122 std::move(offset), std::move(slice_shape), std::move(stride));
echelon's core namespace
Definition: attribute.cpp:10
array_slice< typename container_trait< C >::value_type > make_slice(C &&container, Args...args)
Slice a container.
Definition: array_slice.hpp:89