chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
unary_comparison.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_UNARY_COMPARISON_HPP
2#define CHIHAYA_UNARY_COMPARISON_HPP
3
4#include "H5Cpp.h"
5#include "ritsuko/ritsuko.hpp"
6#include "ritsuko/hdf5/hdf5.hpp"
7
8#include <stdexcept>
9
10#include "utils_public.hpp"
11#include "utils_comparison.hpp"
12#include "utils_unary.hpp"
13#include "utils_misc.hpp"
14#include "utils_type.hpp"
15
21namespace chihaya {
22
27namespace unary_comparison {
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
40 if (!options.details_only) {
41 auto method = internal_unary::load_method(handle);
42 if (!internal_comparison::is_valid_operation(method)) {
43 throw std::runtime_error("unrecognized operation in 'method' (got '" + method + "')");
44 }
45
46 auto side = internal_unary::load_side(handle);
47 if (side != "left" && side != "right") {
48 throw std::runtime_error("'side' should be either 'left' or 'right' (got '" + side + "')");
49 }
50
51 // Checking the value.
52 auto vhandle = ritsuko::hdf5::open_dataset(handle, "value");
53 try {
54 if (version.lt(1, 1, 0)) {
55 if ((seed_details.type == STRING) != (vhandle.getTypeClass() == H5T_STRING)) {
56 throw std::runtime_error("both or neither of 'seed' and 'value' should contain strings");
57 }
58 } else {
59 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(vhandle, "type");
60 auto tt = internal_type::translate_type_1_1(type);
61 if ((tt == STRING) != (seed_details.type == STRING)) {
62 throw std::runtime_error("both or neither of 'seed' and 'value' should contain strings");
63 }
64 internal_type::check_type_1_1(vhandle, tt);
65 }
66
67 internal_misc::validate_missing_placeholder(vhandle, version);
68
69 size_t ndims = vhandle.getSpace().getSimpleExtentNdims();
70 if (ndims == 0) { // scalar operation.
71 if (vhandle.getTypeClass() == H5T_STRING) {
72 ritsuko::hdf5::validate_scalar_string_dataset(vhandle);
73 }
74
75 } else if (ndims == 1) {
76 hsize_t extent;
77 vhandle.getSpace().getSimpleExtentDims(&extent);
78 internal_unary::check_along(handle, version, seed_details.dimensions, extent);
79 if (vhandle.getTypeClass() == H5T_STRING) {
80 ritsuko::hdf5::validate_1d_string_dataset(vhandle, extent, 1000000);
81 }
82
83 } else {
84 throw std::runtime_error("dataset should be scalar or 1-dimensional");
85 }
86
87 } catch (std::exception& e) {
88 throw std::runtime_error("failed to validate 'value'; " + std::string(e.what()));
89 }
90 }
91
92 seed_details.type = BOOLEAN;
93 return seed_details;
94}
95
96}
97
98}
99
100#endif
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: unary_comparison.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.