70 const std::string type_name =
"delayed_array";
71 const auto& vstring = internal_json::extract_version_for_type(metadata.
other, type_name);
72 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
73 if (version.major != 1) {
74 throw std::runtime_error(
"unsupported version '" + vstring +
"'");
79 std::string custom_name =
"custom takane seed array";
81 bool custom_found = (custom_options.array_validate_registry.find(custom_name) != custom_options.array_validate_registry.end());
97 struct ValidateResetter {
98 ValidateResetter(chihaya::Options& o,
const std::string& n,
bool f) : options(o), name(n), found(f) {}
101 options.array_validate_registry.erase(name);
105 chihaya::Options& options;
106 const std::string& name;
109 [[maybe_unused]] ValidateResetter v(custom_options, custom_name, custom_found);
112 custom_options.array_validate_registry[custom_name] = [&](
const H5::Group& handle,
const ritsuko::Version& version, chihaya::Options& ch_options) -> chihaya::ArrayDetails {
113 auto details = chihaya::custom_array::validate(handle, version, ch_options);
115 auto dhandle = ritsuko::hdf5::open_dataset(handle,
"index");
116 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 64,
false)) {
117 throw std::runtime_error(
"'index' should have a datatype that fits into a 64-bit unsigned integer");
120 auto index = ritsuko::hdf5::load_scalar_numeric_dataset<uint64_t>(dhandle);
121 auto seed_path = path /
"seeds" / std::to_string(index);
126 if (seed_dims.size() != details.dimensions.size()) {
127 throw std::runtime_error(
"dimensionality of 'seeds/" + std::to_string(index) +
"' is not consistent with 'dimensions'");
130 for (
size_t d = 0, ndims = seed_dims.size(); d < ndims; ++d) {
131 if (seed_dims[d] != details.dimensions[d]) {
132 throw std::runtime_error(
"dimension extents of 'seeds/" + std::to_string(index) +
"' is not consistent with 'dimensions'");
143 auto apath = path /
"array.h5";
144 auto fhandle = ritsuko::hdf5::open_file(apath);
145 auto ghandle = ritsuko::hdf5::open_group(fhandle,
"delayed_array");
146 ritsuko::Version chihaya_version = chihaya::extract_version(ghandle);
147 if (chihaya_version.lt(1, 1, 0)) {
148 throw std::runtime_error(
"version of the chihaya specification should be no less than 1.1");
153 [[maybe_unused]] internal::DetailsOnlyResetter o(custom_options);
154 custom_options.details_only =
false;
156 chihaya::validate(ghandle, chihaya_version, custom_options);
160 auto seed_path = path /
"seeds";
161 if (std::filesystem::exists(seed_path)) {
162 found = internal_other::count_directory_entries(seed_path);
165 throw std::runtime_error(
"number of objects in 'seeds' is not consistent with the number of 'index' references in 'array.h5'");
177 [[maybe_unused]] internal::DetailsOnlyResetter o(chihaya_options);
178 chihaya_options.details_only =
true;
180 auto apath = path /
"array.h5";
181 auto fhandle = ritsuko::hdf5::open_file(apath);
182 auto ghandle = ritsuko::hdf5::open_group(fhandle,
"delayed_array");
183 auto output = chihaya::validate(ghandle, chihaya_options);
184 return output.dimensions[0];
195 [[maybe_unused]] internal::DetailsOnlyResetter o(chihaya_options);
196 chihaya_options.details_only =
true;
198 auto apath = path /
"array.h5";
199 auto fhandle = ritsuko::hdf5::open_file(apath);
200 auto ghandle = ritsuko::hdf5::open_group(fhandle,
"delayed_array");
201 auto output = chihaya::validate(ghandle, chihaya_options);
202 return std::vector<size_t>(output.dimensions.begin(), output.dimensions.end());