chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
subset_assignment.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_SUBSET_ASSIGNMENT_HPP
2#define CHIHAYA_SUBSET_ASSIGNMENT_HPP
3
4#include "H5Cpp.h"
5#include "ritsuko/hdf5/hdf5.hpp"
6#include "ritsuko/ritsuko.hpp"
7
8#include <stdexcept>
9#include <vector>
10
11#include "utils_public.hpp"
12#include "utils_list.hpp"
13#include "utils_misc.hpp"
14#include "utils_subset.hpp"
15
21namespace chihaya {
22
27namespace subset_assignment {
28
37inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, Options& options) {
38 auto seed_details = internal_misc::load_seed_details(handle, "seed", version, options);
39 const auto& seed_dims = seed_details.dimensions;
40
41 auto value_details = internal_misc::load_seed_details(handle, "value", version, options);
42 if (!options.details_only) {
43 if ((value_details.type == STRING) != (seed_details.type == STRING)) {
44 throw std::runtime_error("both or neither of the 'seed' and 'value' arrays should contain strings");
45 }
46 if (seed_dims.size() != value_details.dimensions.size()) {
47 throw std::runtime_error("'seed' and 'value' arrays should have the same dimensionalities");
48 }
49
50 auto ihandle = ritsuko::hdf5::open_group(handle, "index");
51 auto collected = internal_subset::validate_index_list(ihandle, seed_dims, version);
52 auto expected_dims = seed_dims;
53 for (auto p : collected) {
54 expected_dims[p.first] = p.second;
55 }
56
57 if (!internal_misc::are_dimensions_equal(expected_dims, value_details.dimensions)) {
58 throw std::runtime_error("'value' dimension extents are not consistent with lengths of indices in 'index'");
59 }
60 }
61
62 // Promotion.
63 seed_details.type = std::max(seed_details.type, value_details.type);
64 return seed_details;
65}
66
67}
68
69}
70
71#endif
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: subset_assignment.hpp:37
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
Details about an array.
Definition: utils_public.hpp:36
Validation options.
Definition: utils_public.hpp:66
bool details_only
Definition: utils_public.hpp:71
Various public utilities.