1#ifndef CHIHAYA_UNARY_MATH_HPP
2#define CHIHAYA_UNARY_MATH_HPP
5#include "ritsuko/ritsuko.hpp"
6#include "ritsuko/hdf5/hdf5.hpp"
12#include "utils_unary.hpp"
13#include "utils_misc.hpp"
38 auto seed_details = internal_misc::load_seed_details(handle,
"seed", version, options);
39 if (seed_details.type == STRING) {
40 throw std::runtime_error(
"type of 'seed' should be integer, float or boolean");
44 auto method = internal_unary::load_method(handle);
45 if (method ==
"sign") {
46 seed_details.type = INTEGER;
48 }
else if (method ==
"abs") {
49 seed_details.type = std::max(seed_details.type, INTEGER);
56 method ==
"ceiling" ||
72 seed_details.type = FLOAT;
74 }
else if (method ==
"log") {
76 if (handle.exists(
"base")) {
77 if (handle.childObjType(
"base") != H5O_TYPE_DATASET) {
78 throw std::runtime_error(
"expected 'base' to be a dataset for a log transformation");
80 auto vhandle = handle.openDataSet(
"base");
81 if (!ritsuko::hdf5::is_scalar(vhandle)) {
82 throw std::runtime_error(
"'base' should be a scalar");
85 if (version.lt(1, 1, 0)) {
86 if (vhandle.getTypeClass() != H5T_FLOAT) {
87 throw std::runtime_error(
"'base' should be a floating-point number");
90 if (ritsuko::hdf5::exceeds_float_limit(vhandle, 64)) {
91 throw std::runtime_error(
"'base' should have a datatype that fits into a 64-bit float");
96 seed_details.type = FLOAT;
98 }
else if (method ==
"round" || method ==
"signif") {
100 auto vhandle = ritsuko::hdf5::open_dataset(handle,
"digits");
101 if (!ritsuko::hdf5::is_scalar(vhandle)) {
102 throw std::runtime_error(
"'digits' should be a scalar");
105 if (version.lt(1, 1, 0)) {
106 if (vhandle.getTypeClass() != H5T_INTEGER) {
107 throw std::runtime_error(
"'digits' should be an integer");
110 if (ritsuko::hdf5::exceeds_integer_limit(vhandle, 32,
true)) {
111 throw std::runtime_error(
"'digits' should have a datatype that fits into a 32-bit signed integer");
115 seed_details.type = FLOAT;
118 throw std::runtime_error(
"unrecognized operation in 'method' (got '" + method +
"')");
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: unary_math.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
Various public utilities.