chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
unary_logic.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_UNARY_LOGIC_HPP
2#define CHIHAYA_UNARY_LOGIC_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_logic.hpp"
11#include "utils_unary.hpp"
12#include "utils_type.hpp"
13#include "utils_misc.hpp"
14
21namespace chihaya {
22
27namespace unary_logic {
28
37inline ArrayDetails validate(const H5::Group& handle, const ritsuko::Version& version, Options& options) {
38 auto seed_details = internal_logic::fetch_seed(handle, "seed", version, options);
39
40 if (!options.details_only) {
41 auto method = internal_unary::load_method(handle);
42 if (method != "!" && method != "&&" && method != "||") {
43 throw std::runtime_error("unrecognized operation in 'method' (got '" + method + "')");
44 }
45
46 // Checking the sidedness.
47 if (method != "!") {
48 auto side = internal_unary::load_side(handle);
49 if (side != "left" && side != "right") {
50 throw std::runtime_error("'side' for operation '" + method + "' should be 'left' or 'right' (got '" + side + "')");
51 }
52
53 // Checking the value.
54 auto vhandle = ritsuko::hdf5::open_dataset(handle, "value");
55
56 try {
57 if (version.lt(1, 1, 0)) {
58 if (vhandle.getTypeClass() == H5T_STRING) {
59 throw std::runtime_error("dataset should be integer, float or boolean");
60 }
61 } else {
62 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(vhandle, "type");
63 auto array_type = internal_type::translate_type_1_1(type);
64 if (array_type != INTEGER && array_type != BOOLEAN && array_type != FLOAT) {
65 throw std::runtime_error("dataset should be integer, float or boolean");
66 }
67 internal_type::check_type_1_1(vhandle, array_type);
68 }
69
70 internal_misc::validate_missing_placeholder(vhandle, version);
71
72 size_t ndims = vhandle.getSpace().getSimpleExtentNdims();
73 if (ndims == 0) {
74 // scalar operation.
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 } else {
80 throw std::runtime_error("dataset should be scalar or 1-dimensional");
81 }
82 } catch (std::exception& e) {
83 throw std::runtime_error("failed to validate 'value'; " + std::string(e.what()));
84 }
85 }
86 }
87
88 seed_details.type = BOOLEAN;
89 return seed_details;
90}
91
92}
93
94}
95
96#endif
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: unary_logic.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