18#include "../H5PropertyList.hpp"
30 explicit ElementSet(std::initializer_list<std::size_t> list);
35 explicit ElementSet(std::initializer_list<std::vector<std::size_t>> list);
41 explicit ElementSet(
const std::vector<std::size_t>& element_ids);
46 explicit ElementSet(
const std::vector<std::vector<std::size_t>>& element_ids);
49 std::vector<std::size_t> _ids;
51 template <
typename Derivate>
56 return detail::convertSizeVector<hsize_t>(from);
60 return detail::convertSizeVector<size_t>(from);
67 const std::vector<size_t>& count_ = {},
68 const std::vector<size_t>& stride_ = {},
69 const std::vector<size_t>& block_ = {})
76 std::vector<hsize_t> count_ = {},
77 std::vector<hsize_t> stride_ = {},
78 std::vector<hsize_t> block_ = {}) {
80 slab.
offset = std::move(offset_);
81 slab.count = std::move(count_);
82 slab.stride = std::move(stride_);
83 slab.block = std::move(block_);
89 return std::max(std::max(
offset.size(),
count.size()),
96 auto dims = std::vector<size_t>(n_dims, 0);
98 for (
size_t i = 0; i < n_dims; ++i) {
118 selects.emplace_back(sel, Op::Set);
128 selects.emplace_back(sel, Op::Or);
139 selects.emplace_back(sel, Op::And);
150 selects.emplace_back(sel, Op::Xor);
155 selects.emplace_back(sel, Op::NotA);
160 selects.emplace_back(sel, Op::NotB);
183 H5S_seloper_t convert(Op op)
const {
186 return H5S_SELECT_NOOP;
188 return H5S_SELECT_SET;
190 return H5S_SELECT_OR;
192 return H5S_SELECT_AND;
194 return H5S_SELECT_XOR;
196 return H5S_SELECT_NOTB;
198 return H5S_SELECT_NOTA;
200 return H5S_SELECT_APPEND;
202 return H5S_SELECT_PREPEND;
204 return H5S_SELECT_INVALID;
206 throw DataSpaceException(
"Invalid HyperSlab operation.");
210 struct Select_:
public RegularHyperSlab {
218 std::vector<Select_> selects;
222 auto space = outer_space.
clone();
223 detail::h5s_select_none(space.getId());
228 detail::h5s_select_hyperslab(space.
getId(),
230 sel.offset.empty() ?
nullptr : sel.offset.data(),
231 sel.stride.empty() ? nullptr : sel.stride.data(),
232 sel.count.empty() ? nullptr : sel.count.data(),
233 sel.block.empty() ? nullptr : sel.block.data());
236#if H5_VERSION_GE(1, 10, 6)
238 size_t detect_streak(Select_
const* begin, Select_
const* end, Op op)
const {
239 assert(op == Op::Or);
240 auto it = std::find_if(begin, end, [op](
const Select_& sel) {
return sel.op != op; });
241 return static_cast<size_t>(it - begin);
244 DataSpace combine_selections(
const DataSpace& left_space,
246 const DataSpace& right_space)
const {
247 assert(op == Op::Or);
249 auto left_type = detail::h5s_get_select_type(left_space.getId());
250 auto right_type = detail::h5s_get_select_type(right_space.getId());
254 if (left_type == H5S_SEL_NONE) {
256 }
else if (right_type == H5S_SEL_NONE) {
258 }
else if (left_type == H5S_SEL_ALL) {
260 }
else if (right_type == H5S_SEL_ALL) {
263 return detail::make_data_space(
264 detail::h5s_combine_select(left_space.getId(), convert(op), right_space.getId()));
279 DataSpace reduce_streak(
const DataSpace& outer_space,
280 Select_
const* begin,
283 assert(op == Op::Or);
286 throw std::runtime_error(
"Broken logic in 'DataSpace::reduce_streak'.");
289 std::ptrdiff_t distance = end - begin;
296 Select_
const* mid = begin + distance / 2;
297 auto right_space = reduce_streak(outer_space, begin, mid, op);
298 auto left_space = reduce_streak(outer_space, mid, end, op);
300 return combine_selections(left_space, op, right_space);
304 auto space = space_.
clone();
305 auto n_selects = selects.size();
306 for (
size_t i = 0; i < n_selects; ++i) {
307 auto begin = selects.data() + i;
308 auto end = selects.data() + n_selects;
310 auto n_ors = detect_streak(begin, end, Op::Or);
313 auto right_space = reduce_streak(space_, begin, begin + n_ors, Op::Or);
314 space = combine_selections(space, Op::Or, right_space);
316 }
else if (selects[i].op == Op::None) {
317 detail::h5s_select_none(space.getId());
326 auto space = space_.
clone();
327 for (
const auto& sel: selects) {
328 if (sel.op == Op::None) {
329 detail::h5s_select_none(space.getId());
407 template <
class... Slices>
412 std::vector<size_t> shape;
414 template <
typename Derivate>
419template <
typename Derivate>
449 const std::vector<size_t>& count,
450 const std::vector<size_t>& stride = {},
451 const std::vector<size_t>& block = {})
const;
472 template <
typename T>
485 template <
typename T>
497 template <
typename T>
511 template <
typename T>
522 template <
typename T>
539 template <
typename T>
551 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:23
Definition H5Slice_traits.hpp:111
HyperSlab & notA(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:154
DataSpace apply_impl(const DataSpace &space_) const
Definition H5Slice_traits.hpp:325
HyperSlab & notB(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:159
HyperSlab operator&(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:132
HyperSlab operator^(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:143
HyperSlab operator|(const RegularHyperSlab &sel) const
Definition H5Slice_traits.hpp:121
HyperSlab & operator&=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:138
HyperSlab()
Definition H5Slice_traits.hpp:113
void select_hyperslab(DataSpace &space, const Select_ &sel) const
Definition H5Slice_traits.hpp:227
HyperSlab & operator^=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:149
DataSpace select_none(const DataSpace &outer_space) const
Definition H5Slice_traits.hpp:221
HyperSlab(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:117
HyperSlab & operator|=(const RegularHyperSlab &sel)
Definition H5Slice_traits.hpp:127
DataSpace apply(const DataSpace &space_) const
Definition H5Slice_traits.hpp:164
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:63
Selects the Cartesian product of slices.
Definition H5Slice_traits.hpp:405
HDF5 property Lists.
Definition H5PropertyList.hpp:158
Selection: represent a view on a slice/part of a dataset.
Definition H5Selection.hpp:27
Definition H5Slice_traits.hpp:420
Selection squeezeMemSpace(const std::vector< size_t > &axes) const
Return a Selection with axes squeezed from the memspace.
Definition H5Slice_traits_misc.hpp:465
T read(const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:321
void write(const T &buffer, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:404
Selection select(const HyperSlab &hyperslab) const
Select an hyperslab in the current Slice/Dataset.
Definition H5Slice_traits_misc.hpp:232
Selection reshapeMemSpace(const std::vector< size_t > &dims) const
Return a Selection with a simple memspace with dims.
Definition H5Slice_traits_misc.hpp:476
void read_raw(T *array, const DataType &dtype, const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:375
void write_raw(const T *buffer, const DataType &mem_datatype, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:430
PropertyList< PropertyType::DATASET_XFER > DataTransferProps
Definition H5PropertyList.hpp:200
Definition assert_compatible_spaces.hpp:15
std::vector< size_t > toSTLSizeVector(const std::vector< hsize_t > &from)
Definition H5Slice_traits.hpp:59
std::vector< hsize_t > toHDF5SizeVector(const std::vector< size_t > &from)
Definition H5Slice_traits.hpp:55
Definition H5Slice_traits.hpp:63
size_t rank() const
Definition H5Slice_traits.hpp:88
std::vector< hsize_t > offset
Definition H5Slice_traits.hpp:105
RegularHyperSlab(const std::vector< size_t > &offset_, const std::vector< size_t > &count_={}, const std::vector< size_t > &stride_={}, const std::vector< size_t > &block_={})
Definition H5Slice_traits.hpp:66
std::vector< hsize_t > block
Definition H5Slice_traits.hpp:108
std::vector< size_t > packedDims() const
Dimensions when all gaps are removed.
Definition H5Slice_traits.hpp:94
RegularHyperSlab()=default
std::vector< hsize_t > count
Definition H5Slice_traits.hpp:106
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:75
std::vector< hsize_t > stride
Definition H5Slice_traits.hpp:107