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