51inline void retrieve_dimension_extents(
const H5::DataSet& dhandle, std::vector<hsize_t>& extents) {
72 const std::string type_name =
"dense_array";
73 const auto& vstring = internal_json::extract_version_for_type(metadata.
other, type_name);
74 auto version = ritsuko::parse_version_string(vstring.c_str(), vstring.size(),
true);
75 if (version.major != 1) {
76 throw std::runtime_error(
"unsupported version '" + vstring +
"'");
79 auto handle = ritsuko::hdf5::open_file(path /
"array.h5");
80 auto ghandle = ritsuko::hdf5::open_group(handle,
"dense_array");
81 internal::is_transposed(ghandle);
82 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(ghandle,
"type");
83 std::vector<hsize_t> extents;
85 const char* missing_attr_name =
"missing-value-placeholder";
88 if (version.lt(1, 1, 0)) {
89 throw std::runtime_error(
"unsupported type '" + type +
"'");
92 auto phandle = ritsuko::hdf5::vls::open_pointers(ghandle,
"pointers", 64, 64);
93 internal::retrieve_dimension_extents(phandle, extents);
94 auto hhandle = ritsuko::hdf5::vls::open_heap(ghandle,
"heap");
95 auto hlen = ritsuko::hdf5::get_1d_length(hhandle.getSpace(),
false);
96 ritsuko::hdf5::vls::validate_nd_array<uint64_t, uint64_t>(phandle, extents, hlen, options.
hdf5_buffer_size);
98 if (phandle.attrExists(missing_attr_name)) {
99 auto attr = phandle.openAttribute(missing_attr_name);
100 ritsuko::hdf5::check_string_missing_placeholder_attribute(attr);
104 auto dhandle = ritsuko::hdf5::open_dataset(ghandle,
"data");
105 internal::retrieve_dimension_extents(dhandle, extents);
107 if (type ==
"string") {
108 if (!ritsuko::hdf5::is_utf8_string(dhandle)) {
109 throw std::runtime_error(
"expected string array to have a datatype that can be represented by a UTF-8 encoded string");
111 ritsuko::hdf5::validate_nd_string_dataset(dhandle, extents, options.
hdf5_buffer_size);
113 if (dhandle.attrExists(missing_attr_name)) {
114 auto attr = dhandle.openAttribute(missing_attr_name);
115 ritsuko::hdf5::check_string_missing_placeholder_attribute(attr);
119 if (type ==
"integer") {
120 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 32,
true)) {
121 throw std::runtime_error(
"expected integer array to have a datatype that fits into a 32-bit signed integer");
123 }
else if (type ==
"boolean") {
124 if (ritsuko::hdf5::exceeds_integer_limit(dhandle, 32,
true)) {
125 throw std::runtime_error(
"expected boolean array to have a datatype that fits into a 32-bit signed integer");
127 }
else if (type ==
"number") {
128 if (ritsuko::hdf5::exceeds_float_limit(dhandle, 64)) {
129 throw std::runtime_error(
"expected number array to have a datatype that fits into a 64-bit float");
132 throw std::runtime_error(
"unknown array type '" + type +
"'");
135 if (dhandle.attrExists(missing_attr_name)) {
136 auto attr = dhandle.openAttribute(missing_attr_name);
137 ritsuko::hdf5::check_numeric_missing_placeholder_attribute(dhandle, attr);
142 if (ghandle.exists(
"names")) {
143 internal_array::check_dimnames(ghandle,
"names", extents, options);
154 auto handle = ritsuko::hdf5::open_file(path /
"array.h5");
155 auto ghandle = ritsuko::hdf5::open_group(handle,
"dense_array");
157 auto dhandle = ritsuko::hdf5::open_dataset(ghandle,
"data");
158 auto dspace = dhandle.getSpace();
159 size_t ndims = dspace.getSimpleExtentNdims();
160 std::vector<hsize_t> extents(ndims);
161 dspace.getSimpleExtentDims(extents.data());
163 if (internal::is_transposed(ghandle)) {
164 return extents.back();
166 return extents.front();
177 auto handle = ritsuko::hdf5::open_file(path /
"array.h5");
178 auto ghandle = ritsuko::hdf5::open_group(handle,
"dense_array");
179 auto type = ritsuko::hdf5::open_and_load_scalar_string_attribute(ghandle,
"type");
180 std::vector<hsize_t> extents;
183 auto phandle = ghandle.openDataSet(
"pointers");
184 internal::retrieve_dimension_extents(phandle, extents);
186 auto dhandle = ghandle.openDataSet(
"data");
187 internal::retrieve_dimension_extents(dhandle, extents);
190 if (internal::is_transposed(ghandle)) {
191 return std::vector<size_t>(extents.rbegin(), extents.rend());
193 return std::vector<size_t>(extents.begin(), extents.end());