1#ifndef CHIHAYA_UNARY_ARITHMETIC_HPP
2#define CHIHAYA_UNARY_ARITHMETIC_HPP
5#include "ritsuko/ritsuko.hpp"
6#include "ritsuko/hdf5/hdf5.hpp"
11#include "utils_unary.hpp"
12#include "utils_type.hpp"
13#include "utils_misc.hpp"
14#include "utils_arithmetic.hpp"
27namespace unary_arithmetic {
38 auto seed_details = internal_arithmetic::fetch_seed(handle,
"seed", version, options);
40 auto method = internal_unary::load_method(handle);
42 if (!internal_arithmetic::is_valid_operation(method)) {
43 throw std::runtime_error(
"unrecognized operation in 'method' (got '" + method +
"')");
47 auto side = internal_unary::load_side(handle);
50 if (method !=
"+" && method !=
"-") {
51 throw std::runtime_error(
"'side' cannot be 'none' for operation '" + method +
"'");
53 }
else if (side !=
"left" && side !=
"right") {
54 throw std::runtime_error(
"'side' for operation '" + method +
"' should be 'left' or 'right' (got '" + side +
"')");
62 auto vhandle = ritsuko::hdf5::open_dataset(handle,
"value");
65 if (version.lt(1, 1, 0)) {
66 if (vhandle.getTypeClass() == H5T_STRING) {
67 throw std::runtime_error(
"dataset should be integer, float or boolean");
68 }
else if (vhandle.getTypeClass() == H5T_FLOAT) {
72 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(vhandle,
"type");
73 min_type = internal_type::translate_type_1_1(type);
74 if (min_type != INTEGER && min_type != BOOLEAN && min_type != FLOAT) {
75 throw std::runtime_error(
"dataset should be integer, float or boolean");
77 internal_type::check_type_1_1(vhandle, min_type);
81 internal_misc::validate_missing_placeholder(vhandle, version);
83 auto vspace = vhandle.getSpace();
84 size_t ndims = vspace.getSimpleExtentNdims();
87 }
else if (ndims == 1) {
89 vspace.getSimpleExtentDims(&extent);
90 internal_unary::check_along(handle, version, seed_details.dimensions, extent);
92 throw std::runtime_error(
"dataset should be scalar or 1-dimensional");
96 }
catch (std::exception& e) {
97 throw std::runtime_error(
"failed to validate 'value'; " + std::string(e.what()));
102 seed_details.type = internal_arithmetic::determine_output_type(min_type, seed_details.type, method);
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: unary_arithmetic.hpp:37
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
ArrayType
Definition: utils_public.hpp:27
Details about an array.
Definition: utils_public.hpp:36
Validation options.
Definition: utils_public.hpp:66
bool details_only
Definition: utils_public.hpp:71
Various public utilities.