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
7#include <stdexcept>
8#include <string>
9
10#include "utils_public.hpp"
11#include "utils_misc.hpp"
12#include "utils_type.hpp"
13#include "utils_nary.hpp"
14
20namespace chihaya {
21
30inline ArrayDetails validate_unary_comparison(const H5::Group& group, const ritsuko::Version& version, const Options& options) {
31 auto seed_details = fetch_seed(group, "seed", version, options);
32
33 if (!options.details_only) {
34 auto method = load_scalar_string_dataset(group, "method");
35 if (!is_valid_comparison_operation(method)) {
36 throw std::runtime_error("unrecognized operation in 'method' (got '" + method + "')");
37 }
38
39 auto side = load_scalar_string_dataset(group, "side");
40 if (side != "left" && side != "right") {
41 throw std::runtime_error("'side' should be either 'left' or 'right' (got '" + side + "')");
42 }
43
44 // Checking the value.
45 auto vhandle = group.openDataSet("value");
46 try {
47 ArrayType val_type;
48 if (version.lt(1, 1, 0)) {
49 val_type = translate_type_0_99(vhandle.getTypeClass());
50 } else {
51 auto type = load_scalar_string_attribute(vhandle, "type");
52 val_type = translate_type_1_1(type);
53 check_type_1_1(vhandle, val_type);
54 }
55 if ((val_type == STRING) != (seed_details.type == STRING)) {
56 throw std::runtime_error("both or neither of 'seed' and 'value' should contain strings");
57 }
58
59 validate_missing_placeholder(vhandle, version);
60
61 size_t ndims = vhandle.getSpace().getSimpleExtentNdims();
62 if (ndims == 0) { // scalar operation.
63 if (vhandle.getTypeClass() == H5T_STRING) {
64 ritsuko::hdf5::validate_scalar_string(vhandle);
65 }
66
67 } else if (ndims == 1) {
68 hsize_t extent;
69 vhandle.getSpace().getSimpleExtentDims(&extent);
70 check_unary_along(group, version, seed_details.dimensions, extent);
71 if (vhandle.getTypeClass() == H5T_STRING) {
72 ritsuko::hdf5::validate_1d_strings(vhandle, extent);
73 }
74
75 } else {
76 throw std::runtime_error("dataset should be scalar or 1-dimensional");
77 }
78
79 } catch (std::exception& e) {
80 throw std::runtime_error("failed to validate 'value'; " + std::string(e.what()));
81 }
82 }
83
84 seed_details.type = BOOLEAN;
85 return seed_details;
86}
87
88}
89
90#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:20
ArrayDetails validate_unary_comparison(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition unary_comparison.hpp:30
ArrayType
Definition utils_public.hpp:28
Details about an array.
Definition utils_public.hpp:37
Validation options.
Definition utils_public.hpp:67
bool details_only
Definition utils_public.hpp:72
Various public utilities.