chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
binary_comparison.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_BINARY_COMPARISON_HPP
2#define CHIHAYA_BINARY_COMPARISON_HPP
3
4#include "H5Cpp.h"
5#include "ritsuko/ritsuko.hpp"
6
7#include <stdexcept>
8#include <exception>
9#include <vector>
10
11#include "utils_public.hpp"
12#include "utils_misc.hpp"
13#include "utils_nary.hpp"
14
20namespace chihaya {
21
34inline ArrayDetails validate_binary_comparison(const H5::Group& group, const ritsuko::Version& version, const Options& options) {
35 ArrayDetails left_details;
36 try {
37 auto lhandle = group.openGroup("left");
38 left_details = validate(lhandle, version, options);
39 } catch (...) {
40 std::throw_with_nested(std::runtime_error("failed to validate 'left'"));
41 }
42
43 ArrayDetails right_details;
44 try {
45 auto rhandle = group.openGroup("right");
46 right_details = validate(rhandle, version, options);
47 } catch (...) {
48 std::throw_with_nested(std::runtime_error("failed to validate 'right'"));
49 }
50
51 if (!options.details_only) {
52 if (!are_dimensions_equal(left_details.dimensions, right_details.dimensions)) {
53 throw std::runtime_error("'left' and 'right' should have the same dimensions");
54 }
55
56 if ((left_details.type == STRING) != (right_details.type == STRING)) {
57 throw std::runtime_error("both or neither of 'left' and 'right' should contain strings");
58 }
59
60 try {
61 auto mhandle = group.openDataSet("method");
62 auto method = read_scalar_string_dataset(mhandle);
63 if (!is_valid_comparison_operation(method)) {
64 throw std::runtime_error("unrecognized operation '" + method + "'");
65 }
66 } catch (...) {
67 std::throw_with_nested(std::runtime_error("failed to validate 'method'"));
68 }
69 }
70
71 left_details.type = BOOLEAN;
72 return left_details;
73}
74
75}
76
77#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:21
ArrayDetails validate_binary_comparison(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition binary_comparison.hpp:34
ArrayDetails validate(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition validate.hpp:96
Details about an array.
Definition utils_public.hpp:38
std::vector< std::size_t > dimensions
Definition utils_public.hpp:58
ArrayType type
Definition utils_public.hpp:52
Options for validate().
Definition utils_public.hpp:79
bool details_only
Definition utils_public.hpp:84
Various public utilities.