29 explicit ElementSet(std::initializer_list<std::size_t> list);
34 explicit ElementSet(std::initializer_list<std::vector<std::size_t>> list);
40 explicit ElementSet(
const std::vector<std::size_t>& element_ids);
45 explicit ElementSet(
const std::vector<std::vector<std::size_t>>& element_ids);
48 std::vector<std::size_t> _ids;
50 template <
typename Derivate>
56template <
class To,
class From>
57inline std::vector<To> convertSizeVector(
const std::vector<From>& from) {
58 std::vector<To> to(from.size());
59 std::copy(from.cbegin(), from.cend(), to.begin());
66 return detail::convertSizeVector<hsize_t>(from);
70 return detail::convertSizeVector<size_t>(from);
77 std::vector<size_t> count_ = {},
78 std::vector<size_t> stride_ = {},
79 std::vector<size_t> block_ = {})
86 std::vector<hsize_t> count_ = {},
87 std::vector<hsize_t> stride_ = {},
88 std::vector<hsize_t> block_ = {}) {
92 slab.stride = stride_;
99 return std::max(std::max(
offset.size(),
count.size()),
105 auto n_dims =
rank();
106 auto dims = std::vector<size_t>(n_dims, 0);
108 for (
size_t i = 0; i < n_dims; ++i) {
128 selects.emplace_back(sel, Op::Set);
138 selects.emplace_back(sel, Op::Or);
149 selects.emplace_back(sel, Op::And);
160 selects.emplace_back(sel, Op::Xor);
165 selects.emplace_back(sel, Op::NotA);
170 selects.emplace_back(sel, Op::NotB);
193 H5S_seloper_t convert(Op op)
const {
196 return H5S_SELECT_NOOP;
198 return H5S_SELECT_SET;
200 return H5S_SELECT_OR;
202 return H5S_SELECT_AND;
204 return H5S_SELECT_XOR;
206 return H5S_SELECT_NOTB;
208 return H5S_SELECT_NOTA;
210 return H5S_SELECT_APPEND;
212 return H5S_SELECT_PREPEND;
214 return H5S_SELECT_INVALID;
216 throw DataSpaceException(
"Invalid HyperSlab operation.");
220 struct Select_:
public RegularHyperSlab {
228 std::vector<Select_> selects;
232 auto space = outer_space.
clone();
233 detail::h5s_select_none(space.getId());
238 detail::h5s_select_hyperslab(space.
getId(),
240 sel.offset.empty() ?
nullptr : sel.offset.data(),
241 sel.stride.empty() ? nullptr : sel.stride.data(),
242 sel.count.empty() ? nullptr : sel.count.data(),
243 sel.block.empty() ? nullptr : sel.block.data());
246#if H5_VERSION_GE(1, 10, 6)
248 size_t detect_streak(Select_
const* begin, Select_
const* end, Op op)
const {
249 assert(op == Op::Or);
250 auto it = std::find_if(begin, end, [op](
const Select_& sel) {
return sel.op != op; });
251 return static_cast<size_t>(it - begin);
257 assert(op == Op::Or);
259 auto left_type = detail::h5s_get_select_type(left_space.getId());
260 auto right_type = detail::h5s_get_select_type(right_space.getId());
264 if (left_type == H5S_SEL_NONE) {
266 }
else if (right_type == H5S_SEL_NONE) {
268 }
else if (left_type == H5S_SEL_ALL) {
270 }
else if (right_type == H5S_SEL_ALL) {
273 return detail::make_data_space(
274 detail::h5s_combine_select(left_space.getId(), convert(op), right_space.getId()));
290 Select_
const* begin,
293 assert(op == Op::Or);
296 throw std::runtime_error(
"Broken logic in 'DataSpace::reduce_streak'.");
299 std::ptrdiff_t distance = end - begin;
306 Select_
const* mid = begin + distance / 2;
307 auto right_space = reduce_streak(outer_space, begin, mid, op);
308 auto left_space = reduce_streak(outer_space, mid, end, op);
310 return combine_selections(left_space, op, right_space);
314 auto space = space_.
clone();
315 auto n_selects = selects.size();
316 for (
size_t i = 0; i < n_selects; ++i) {
317 auto begin = selects.data() + i;
318 auto end = selects.data() + n_selects;
320 auto n_ors = detect_streak(begin, end, Op::Or);
323 auto right_space = reduce_streak(space_, begin, begin + n_ors, Op::Or);
324 space = combine_selections(space, Op::Or, right_space);
326 }
else if (selects[i].op == Op::None) {
327 detail::h5s_select_none(space.getId());
336 auto space = space_.
clone();
337 for (
const auto& sel: selects) {
338 if (sel.op == Op::None) {
339 detail::h5s_select_none(space.getId());
349template <
typename Derivate>
379 const std::vector<size_t>& count,
380 const std::vector<size_t>& stride = {},
381 const std::vector<size_t>& block = {})
const;
395 template <
typename T>
408 template <
typename T>
422 template <
typename T>
438 template <
typename T>
450 template <
typename T>
464 template <
typename T>
475 template <
typename T>
492 template <
typename T>
504 template <
typename T>
Class representing the space (dimensions) of a DataSet.
Definition H5DataSpace.hpp:39
DataSpace clone() const
Create a copy of the DataSpace which will have different id.
Definition H5Dataspace_misc.hpp:94
HDF5 Data Type.
Definition H5DataType.hpp:61
Definition H5Slice_traits.hpp:22
ElementSet(std::initializer_list< std::size_t > list)
Create a list of points of N-dimension for selection.
Definition H5Slice_traits_misc.hpp:51
Definition H5Slice_traits.hpp:121
HyperSlab & notA(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:164
DataSpace apply_impl(const DataSpace &space_) const
Definition H5Slice_traits.hpp:335
HyperSlab & notB(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:169
HyperSlab operator&(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:142
HyperSlab operator^(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:153
HyperSlab operator|(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:131
HyperSlab & operator&=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:148
HyperSlab()
Definition H5Slice_traits.hpp:123
void select_hyperslab(DataSpace &space, const Select_ &sel) const
Definition H5Slice_traits.hpp:237
HyperSlab & operator^=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:159
DataSpace select_none(const DataSpace &outer_space) const
Definition H5Slice_traits.hpp:231
HyperSlab(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:127
HyperSlab & operator|=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:137
DataSpace apply(const DataSpace &space_) const
Definition H5Slice_traits.hpp:174
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
HDF5 property Lists.
Definition H5PropertyList.hpp:160
Selection: represent a view on a slice/part of a dataset.
Definition H5Selection.hpp:27
Definition H5Slice_traits.hpp:350
T read(const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:160
void write(const T &buffer, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:256
Selection select(const HyperSlab &hyperslab) const
Select an hyperslab in the current Slice/Dataset.
Definition H5Slice_traits_misc.hpp:82
void read_raw(T *array, const DataType &dtype, const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:227
void write_raw(const T *buffer, const DataType &mem_datatype, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:281
PropertyList< PropertyType::DATASET_XFER > DataTransferProps
Definition H5PropertyList.hpp:203
Definition H5_definitions.hpp:22
std::vector< size_t > toSTLSizeVector(const std::vector< hsize_t > &from)
Definition H5Slice_traits.hpp:69
std::vector< hsize_t > toHDF5SizeVector(const std::vector< size_t > &from)
Definition H5Slice_traits.hpp:65
Definition H5Slice_traits.hpp:73
size_t rank() const
Definition H5Slice_traits.hpp:98
std::vector< hsize_t > offset
Definition H5Slice_traits.hpp:115
std::vector< hsize_t > block
Definition H5Slice_traits.hpp:118
std::vector< size_t > packedDims() const
Dimensions when all gaps are removed.
Definition H5Slice_traits.hpp:104
RegularHyperSlab(std::vector< size_t > offset_, std::vector< size_t > count_={}, std::vector< size_t > stride_={}, std::vector< size_t > block_={})
Definition H5Slice_traits.hpp:76
RegularHyperSlab()=default
std::vector< hsize_t > count
Definition H5Slice_traits.hpp:116
static RegularHyperSlab fromHDF5Sizes(std::vector< hsize_t > offset_, std::vector< hsize_t > count_={}, std::vector< hsize_t > stride_={}, std::vector< hsize_t > block_={})
Definition H5Slice_traits.hpp:85
std::vector< hsize_t > stride
Definition H5Slice_traits.hpp:117