1#ifndef CHIHAYA_VALIDATE_HPP
2#define CHIHAYA_VALIDATE_HPP
5#include "ritsuko/ritsuko.hpp"
6#include "ritsuko/hdf5/hdf5.hpp"
50inline auto default_operation_registry() {
51 std::unordered_map<std::string, std::function<ArrayDetails(
const H5::Group&,
const ritsuko::Version&, Options&)> > registry;
52 registry[
"subset"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return subset::validate(h, v, o); };
53 registry[
"combine"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return combine::validate(h, v, o); };
54 registry[
"transpose"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return transpose::validate(h, v, o); };
55 registry[
"dimnames"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return dimnames::validate(h, v, o); };
56 registry[
"subset assignment"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return subset_assignment::validate(h, v, o); };
57 registry[
"unary arithmetic"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return unary_arithmetic::validate(h, v, o); };
58 registry[
"unary comparison"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return unary_comparison::validate(h, v, o); };
59 registry[
"unary logic"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return unary_logic::validate(h, v, o); };
60 registry[
"unary math"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return unary_math::validate(h, v, o); };
61 registry[
"unary special check"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return unary_special_check::validate(h, v, o); };
62 registry[
"binary arithmetic"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return binary_arithmetic::validate(h, v, o); };
63 registry[
"binary comparison"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return binary_comparison::validate(h, v, o); };
64 registry[
"binary logic"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return binary_logic::validate(h, v, o); };
65 registry[
"matrix product"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return matrix_product::validate(h, v, o); };
69inline auto default_array_registry() {
70 std::unordered_map<std::string, std::function<ArrayDetails(
const H5::Group&,
const ritsuko::Version&, Options&)> > registry;
71 registry[
"dense array"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return dense_array::validate(h, v, o); };
72 registry[
"sparse matrix"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return sparse_matrix::validate(h, v, o); };
73 registry[
"constant array"] = [](
const H5::Group& h,
const ritsuko::Version& v, Options& o) -> ArrayDetails {
return constant_array::validate(h, v, o); };
93 auto dtype = ritsuko::hdf5::open_and_load_scalar_string_attribute(handle,
"delayed_type");
96 if (dtype ==
"array") {
97 auto atype = ritsuko::hdf5::open_and_load_scalar_string_attribute(handle,
"delayed_array");
100 auto cit = custom.find(atype);
101 if (cit != custom.end()) {
103 output = (cit->second)(handle, version, options);
104 }
catch (std::exception& e) {
105 throw std::runtime_error(
"failed to validate delayed array of type '" + atype +
"'; " + std::string(e.what()));
109 static const auto global = internal::default_array_registry();
110 auto git = global.find(atype);
111 if (git != global.end()) {
113 output = (git->second)(handle, version, options);
114 }
catch (std::exception& e) {
115 throw std::runtime_error(
"failed to validate delayed array of type '" + atype +
"'; " + std::string(e.what()));
117 }
else if (atype.rfind(
"custom ", 0) != std::string::npos) {
120 }
catch (std::exception& e) {
121 throw std::runtime_error(
"failed to validate delayed array of type '" + atype +
"'; " + std::string(e.what()));
123 }
else if (atype.rfind(
"external hdf5 ", 0) != std::string::npos && version.lt(1, 1, 0)) {
126 }
catch (std::exception& e) {
127 throw std::runtime_error(
"failed to validate delayed array of type '" + atype +
"'; " + std::string(e.what()));
130 throw std::runtime_error(
"unknown array type '" + atype +
"'");
134 }
else if (dtype ==
"operation") {
135 auto otype = ritsuko::hdf5::open_and_load_scalar_string_attribute(handle,
"delayed_operation");
138 auto cit = custom.find(otype);
139 if (cit != custom.end()) {
141 output = (cit->second)(handle, version, options);
142 }
catch (std::exception& e) {
143 throw std::runtime_error(
"failed to validate delayed operation of type '" + otype +
"'; " + std::string(e.what()));
147 static const auto global = internal::default_operation_registry();
148 auto git = global.find(otype);
149 if (git != global.end()) {
151 output = (git->second)(handle, version, options);
152 }
catch (std::exception& e) {
153 throw std::runtime_error(
"failed to validate delayed operation of type '" + otype +
"'; " + std::string(e.what()));
156 throw std::runtime_error(
"unknown operation type '" + otype +
"'");
161 throw std::runtime_error(
"unknown delayed type '" + dtype +
"'");
177 ritsuko::Version version;
179 if (handle.attrExists(
"delayed_version")) {
180 auto ahandle = handle.openAttribute(
"delayed_version");
181 if (!ritsuko::hdf5::is_utf8_string(ahandle)) {
182 throw std::runtime_error(
"expected 'delayed_version' to use a datatype that can be represented by a UTF-8 encoded string");
185 auto vstring = ritsuko::hdf5::load_scalar_string_attribute(ahandle);
186 if (vstring ==
"1.0.0") {
189 version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
220 H5::H5File handle(path, H5F_ACC_RDONLY);
221 auto ghandle = handle.openGroup(name);
235 H5::H5File handle(path, H5F_ACC_RDONLY);
237 auto ghandle = handle.openGroup(name);
Validation for delayed binary arithmetic operations.
Validation for delayed binary comparisons.
Validation for delayed binary logical operations.
Validation for delayed combining operations.
Constant array, stored inside the file.
Validation for custom third-party arrays.
Dense array, stored inside the file.
Validation for delayed dimnames assignment.
Validation for external HDF5 arrays.
Validation for delayed matrix products.
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: custom_array.hpp:31
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: external_hdf5.hpp:31
Namespace for all chihaya functions.
Definition: binary_arithmetic.hpp:22
ritsuko::Version extract_version(const H5::Group &handle)
Definition: validate.hpp:176
ArrayDetails validate(const H5::Group &handle, const ritsuko::Version &version, Options &options)
Definition: validate.hpp:92
Validation for compressed sparse column matrices.
Details about an array.
Definition: utils_public.hpp:36
Validation options.
Definition: utils_public.hpp:66
std::unordered_map< std::string, std::function< ArrayDetails(const H5::Group &, const ritsuko::Version &, Options &)> > array_validate_registry
Definition: utils_public.hpp:77
std::unordered_map< std::string, std::function< ArrayDetails(const H5::Group &, const ritsuko::Version &, Options &)> > operation_validate_registry
Definition: utils_public.hpp:83
Validation for delayed subsets.
Validation for delayed subset assignment.
Validation for delayed transposition.
Validation for delayed unary arithmetic operations.
Validation for delayed unary comparisons.
Validation for delayed unary logic operations.
Validation for delayed unary math operations.
Validation for delayed unary special checks.
Various public utilities.