chihaya
Validating delayed array operations in HDF5
Loading...
Searching...
No Matches
unary_math.hpp
Go to the documentation of this file.
1#ifndef CHIHAYA_UNARY_MATH_HPP
2#define CHIHAYA_UNARY_MATH_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_nary.hpp"
13
19namespace chihaya {
20
29inline ArrayDetails validate_unary_math(const H5::Group& group, const ritsuko::Version& version, const Options& options) {
30 auto seed_details = fetch_numeric_seed(group, "seed", version, options);
31 if (seed_details.type == STRING) {
32 throw std::runtime_error("type of 'seed' should be integer, float or boolean");
33 }
34
35 // Checking the method.
36 auto method = load_scalar_string_dataset(group, "method");
37 if (method == "sign") {
38 seed_details.type = INTEGER;
39
40 } else if (method == "abs") {
41 seed_details.type = std::max(seed_details.type, INTEGER);
42
43 } else if (method == "log") {
44 if (!options.details_only) {
45 if (group.exists("base")) {
46 auto vhandle = group.openDataSet("base");
47 if (vhandle.getSpace().getSimpleExtentNdims() != 0) {
48 throw std::runtime_error("'base' should be a scalar");
49 }
50 if (version.lt(1, 1, 0)) {
51 if (vhandle.getTypeClass() != H5T_FLOAT) {
52 throw std::runtime_error("'base' should be a floating-point number");
53 }
54 } else {
55 if (ritsuko::hdf5::exceeds_float_limit(vhandle, 64)) {
56 throw std::runtime_error("'base' should have a datatype that fits into a 64-bit float");
57 }
58 }
59 }
60 }
61 seed_details.type = FLOAT;
62
63 } else if (method == "round" || method == "signif") {
64 if (!options.details_only) {
65 auto vhandle = group.openDataSet("digits");
66 if (vhandle.getSpace().getSimpleExtentNdims() != 0) {
67 throw std::runtime_error("'digits' should be a scalar");
68 }
69
70 if (version.lt(1, 1, 0)) {
71 if (vhandle.getTypeClass() != H5T_INTEGER) {
72 throw std::runtime_error("'digits' should be an integer");
73 }
74 } else {
75 if (ritsuko::hdf5::exceeds_integer_limit(vhandle, 32, true)) {
76 throw std::runtime_error("'digits' should have a datatype that fits into a 32-bit signed integer");
77 }
78 }
79 }
80 seed_details.type = FLOAT;
81
82 } else if (is_other_math(method)) {
83 seed_details.type = FLOAT;
84
85 } else {
86 throw std::runtime_error("unrecognized operation in 'method' (got '" + method + "')");
87 }
88
89 return seed_details;
90}
91
92}
93
94#endif
Namespace for all chihaya functions.
Definition binary_arithmetic.hpp:20
ArrayDetails validate_unary_math(const H5::Group &group, const ritsuko::Version &version, const Options &options)
Definition unary_math.hpp:29
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.