chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
combine.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_COMBINE_HPP
2#define CHIHAYA_COMBINE_HPP
3
4#include "H5Cpp.h"
5#include "ritsuko/ritsuko.hpp"
7
8#include <stdexcept>
9#include <vector>
10#include <string>
11#include <cstddef>
12
13#include "utils_public.hpp"
14#include "utils_misc.hpp"
15#include "utils_list.hpp"
16#include "utils_dimensions.hpp"
17
23namespace chihaya {
24
33inline ArrayDetails validate_combine(const H5::Group& group, const ritsuko::Version& version, const Options& options) {
34 std::uint64_t along;
35 try {
36 along = load_along(group.openDataSet("along"), version);
37 } catch (...) {
38 std::throw_with_nested(std::runtime_error("failed to validate 'along'"));
39 }
40
41 ArrayType type = BOOLEAN;
42 std::vector<std::size_t> dimensions;
43
44 try {
45 const auto shandle = group.openGroup("seeds");
46 auto list_params = validate_list(shandle, version);
47 if (list_params.present.size() != list_params.length) {
48 throw std::runtime_error("missing elements in the 'seeds' list");
49 }
50
51 bool first = true;
52 I<decltype(list_params.length)> num_strings = 0;
53
54 for (auto& p : list_params.present) {
55 try {
56 auto sdhandle = shandle.openGroup(p.second);
57 auto cur_seed = validate(sdhandle, version, options);
58
59 if (first) {
60 type = cur_seed.type;
61 dimensions = std::move(cur_seed.dimensions);
62 if (sanisizer::is_greater_than_or_equal(along, dimensions.size())) {
63 throw std::runtime_error("'along' should be less than the seed dimensionality");
64 }
65 first = false;
66
67 } else {
68 if (type < cur_seed.type) {
69 type = cur_seed.type;
70 }
71 const auto ndims = dimensions.size();
72 if (ndims != cur_seed.dimensions.size()) {
73 throw std::runtime_error("detected dimensionality mismatch between seeds");
74 }
75 for (I<decltype(ndims)> d = 0; d < ndims; ++d) {
76 if (sanisizer::is_equal(d, along)) {
77 dimensions[d] = sanisizer::sum<std::size_t>(dimensions[d], cur_seed.dimensions[d]);
78 } else if (dimensions[d] != cur_seed.dimensions[d]) {
79 throw std::runtime_error("inconsistent dimension extents between seeds");
80 }
81 }
82 }
83
84 num_strings += (cur_seed.type == STRING);
85 } catch (...) {
86 std::throw_with_nested(std::runtime_error("failed to validate seed " + p.second));
87 }
88 }
89
90 if (num_strings != 0 && num_strings != list_params.length) {
91 throw std::runtime_error("either none or all of the arrays to be combined should contain strings");
92 }
93 } catch (...) {
94 std::throw_with_nested(std::runtime_error("failed to validate 'seeds'"));
95 }
96
97 return ArrayDetails(type, std::move(dimensions));
98}
99
100}
101
102#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:20
ArrayDetails validate(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition validate.hpp:90
ArrayDetails validate_combine(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition combine.hpp:33
ArrayType
Definition utils_public.hpp:29
constexpr bool is_equal(Left_ left, Right_ right)
constexpr bool is_greater_than_or_equal(Left_ left, Right_ right)
constexpr Dest_ sum(First_ first, Args_... more)
Details about an array.
Definition utils_public.hpp:38
Options for validate().
Definition utils_public.hpp:79
Various public utilities.