From de1ce8db6252c46f171ea51f7a613731dfd0d159 Mon Sep 17 00:00:00 2001 From: Thoemi09 Date: Fri, 15 Nov 2024 23:04:33 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20github.io=20from=20@=20TRIQS/h?= =?UTF-8?q?5@edb02b336d38f5de78662fa41d92cb100eec9ee9=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/unstable/array_8hpp_source.html | 152 ++++----- .../array__interface_8cpp_source.html | 203 ++++++------ .../array__interface_8hpp_source.html | 284 +++-------------- docs/unstable/changelog.html | 2 +- docs/unstable/complex_8hpp_source.html | 57 +--- ...rable.html => concepth5_1_1_storable.html} | 16 +- .../dir_4fef79e7177ba769987a8da36c892c5f.html | 2 +- .../dir_6c89d1ed406002b4e6ebce07fb51a507.html | 2 +- .../dir_e68e8157741866f444e17edd764ebbae.html | 2 +- docs/unstable/doxygen_crawl.html | 68 ++-- docs/unstable/ex2.html | 8 +- docs/unstable/file_8cpp_source.html | 109 ++++--- docs/unstable/file_8hpp_source.html | 139 +-------- docs/unstable/format_8cpp_source.html | 47 ++- docs/unstable/format_8hpp_source.html | 180 +++-------- docs/unstable/generic_8hpp.html | 2 +- docs/unstable/generic_8hpp_source.html | 173 ++--------- docs/unstable/group_8cpp_source.html | 141 ++++----- docs/unstable/group_8hpp_source.html | 213 ++----------- docs/unstable/group__h5__types.html | 6 +- docs/unstable/group__readwrite.html | 2 +- docs/unstable/group__rw__generic.html | 2 +- docs/unstable/group__rw__map.html | 4 +- docs/unstable/group__rw__optional.html | 4 +- docs/unstable/group__rw__pair.html | 4 +- docs/unstable/group__rw__string.html | 20 +- docs/unstable/group__rw__tuple.html | 4 +- docs/unstable/group__rw__variant.html | 4 +- docs/unstable/group__rw__vector.html | 4 +- docs/unstable/group__utilities.html | 2 +- docs/unstable/h5_8hpp.html | 2 +- docs/unstable/h5_8hpp_source.html | 99 +++--- docs/unstable/macros_8hpp_source.html | 143 ++------- docs/unstable/map_8hpp.html | 4 +- docs/unstable/map_8hpp_source.html | 94 ++---- ...ChangeLog.html => md_h5_2_change_log.html} | 2 +- docs/unstable/menudata.js | 14 +- docs/unstable/navtreedata.js | 14 +- docs/unstable/navtreeindex0.js | 14 +- docs/unstable/object_8cpp_source.html | 193 ++++++------ docs/unstable/object_8hpp_source.html | 234 +++----------- docs/unstable/optional_8hpp.html | 4 +- docs/unstable/optional_8hpp_source.html | 72 ++--- docs/unstable/pair_8hpp.html | 4 +- docs/unstable/pair_8hpp_source.html | 86 ++---- docs/unstable/scalar_8hpp_source.html | 170 +++------- docs/unstable/search/all_6.js | 2 +- docs/unstable/search/all_b.js | 24 +- docs/unstable/search/classes_5.js | 12 +- docs/unstable/search/concepts_0.js | 2 +- docs/unstable/search/functions_6.js | 10 +- docs/unstable/search/pages_4.js | 2 +- docs/unstable/serialization_8hpp_source.html | 63 +--- docs/unstable/string_8cpp_source.html | 225 +++++++------- docs/unstable/string_8hpp_source.html | 292 +++--------------- .../structh5_1_1hdf5__format__impl.html | 4 +- ...key_t_00_01value_t_01_4_01_4-members.html} | 4 +- ...map_3_01key_t_00_01value_t_01_4_01_4.html} | 6 +- ...1_1optional_3_01_t_01_4_01_4-members.html} | 4 +- ...3_01std_1_1optional_3_01_t_01_4_01_4.html} | 6 +- ...r_3_01_t1_00_01_t2_01_4_01_4-members.html} | 4 +- ...d_1_1pair_3_01_t1_00_01_t2_01_4_01_4.html} | 6 +- ...tuple_3_01_t_8_8_8_01_4_01_4-members.html} | 4 +- ...1std_1_1tuple_3_01_t_8_8_8_01_4_01_4.html} | 6 +- ...riant_3_01_t_8_8_8_01_4_01_4-members.html} | 4 +- ...td_1_1variant_3_01_t_8_8_8_01_4_01_4.html} | 6 +- ...d_1_1vector_3_01_t_01_4_01_4-members.html} | 4 +- ...l_3_01std_1_1vector_3_01_t_01_4_01_4.html} | 6 +- docs/unstable/tuple_8hpp.html | 4 +- docs/unstable/tuple_8hpp_source.html | 90 ++---- docs/unstable/utils_8hpp_source.html | 143 ++------- docs/unstable/variant_8hpp.html | 4 +- docs/unstable/variant_8hpp_source.html | 90 ++---- docs/unstable/vector_8cpp_source.html | 86 +++--- docs/unstable/vector_8hpp.html | 4 +- docs/unstable/vector_8hpp_source.html | 236 ++++---------- 76 files changed, 1330 insertions(+), 3028 deletions(-) rename docs/unstable/{concepth5_1_1Storable.html => concepth5_1_1_storable.html} (77%) rename docs/unstable/{md_h5_2ChangeLog.html => md_h5_2_change_log.html} (98%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1map_3_01keyT_00_01valueT_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1map_3_01key_t_00_01value_t_01_4_01_4-members.html} (94%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1map_3_01keyT_00_01valueT_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1map_3_01key_t_00_01value_t_01_4_01_4.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1optional_3_01T_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1optional_3_01_t_01_4_01_4-members.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1optional_3_01T_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1optional_3_01_t_01_4_01_4.html} (96%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1pair_3_01T1_00_01T2_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1pair_3_01_t1_00_01_t2_01_4_01_4-members.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1pair_3_01T1_00_01T2_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1pair_3_01_t1_00_01_t2_01_4_01_4.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1tuple_3_01T_8_8_8_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1tuple_3_01_t_8_8_8_01_4_01_4-members.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1tuple_3_01T_8_8_8_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1tuple_3_01_t_8_8_8_01_4_01_4.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1variant_3_01T_8_8_8_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1variant_3_01_t_8_8_8_01_4_01_4-members.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1variant_3_01T_8_8_8_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1variant_3_01_t_8_8_8_01_4_01_4.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1vector_3_01T_01_4_01_4-members.html => structh5_1_1hdf5__format__impl_3_01std_1_1vector_3_01_t_01_4_01_4-members.html} (95%) rename docs/unstable/{structh5_1_1hdf5__format__impl_3_01std_1_1vector_3_01T_01_4_01_4.html => structh5_1_1hdf5__format__impl_3_01std_1_1vector_3_01_t_01_4_01_4.html} (95%) diff --git a/docs/unstable/array_8hpp_source.html b/docs/unstable/array_8hpp_source.html index 53bb16d4..d0bdd29a 100644 --- a/docs/unstable/array_8hpp_source.html +++ b/docs/unstable/array_8hpp_source.html @@ -127,154 +127,122 @@
14//
15// Authors: Thomas Hahn, Nils Wentzell
16
-
17/**
-
18 * @file
-
19 * @brief Provides functions to read/write std::array objects from/to HDF5.
-
20 */
-
21
-
22#ifndef LIBH5_STL_ARRAY_HPP
-
23#define LIBH5_STL_ARRAY_HPP
+
22#ifndef LIBH5_STL_ARRAY_HPP
+
23#define LIBH5_STL_ARRAY_HPP
24
-
25#include "../array_interface.hpp"
-
26#include "../complex.hpp"
-
27#include "../macros.hpp"
+
25#include "../array_interface.hpp"
+
26#include "../complex.hpp"
+
27#include "../macros.hpp"
28
-
29#include <algorithm>
-
30#include <array>
-
31#include <iostream>
-
32#include <string>
-
33#include <type_traits>
+
29#include <algorithm>
+
30#include <array>
+
31#include <iostream>
+
32#include <string>
+
33#include <type_traits>
34
-
35namespace h5 {
+
35namespace h5 {
36
-
37 /**
-
38 * @addtogroup rw_array
-
39 * @{
-
40 */
-
41
-
42 /**
-
43 * @brief Write a std::array to an HDF5 dataset/subgroup.
-
44 *
-
45 * @tparam T Value type of the std::array.
-
46 * @tparam N Size of the std::array.
-
47 * @param g h5::group in which the dataset/subgroup is created.
-
48 * @param name Name of the dataset/subgroup to which the std::array is written.
-
49 * @param a std::array to be written.
-
50 */
-
51 template <typename T, size_t N>
+
51 template <typename T, size_t N>
-
52 void h5_write(group g, std::string const &name, std::array<T, N> const &a) {
+
52 void h5_write(group g, std::string const &name, std::array<T, N> const &a) {
53 if constexpr (std::is_same_v<T, std::string>) {
54 // array of strings
-
55 auto char_arr = std::array<const char *, N>{};
+
55 auto char_arr = std::array<const char *, N>{};
56 std::transform(cbegin(a), cend(a), begin(char_arr), [](std::string const &s) { return s.c_str(); });
-
57 h5_write(g, name, char_arr);
-
58 } else if constexpr (std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or std::is_same_v<T, char *>
-
59 or std::is_same_v<T, const char *>) {
+
57 h5_write(g, name, char_arr);
+
58 } else if constexpr (std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or std::is_same_v<T, char *>
+
59 or std::is_same_v<T, const char *>) {
60 // array of arithmetic/complex types or char* or const char*
-
61 h5::array_interface::array_view v{hdf5_type<T>(), (void *)a.data(), 1, is_complex_v<T>};
-
62 v.slab.count[0] = N;
-
63 v.slab.stride[0] = 1;
-
64 v.parent_shape[0] = N;
-
65 h5::array_interface::write(g, name, v, true);
+ +
62 v.slab.count[0] = N;
+
63 v.slab.stride[0] = 1;
+
64 v.parent_shape[0] = N;
+
65 h5::array_interface::write(g, name, v, true);
66 } else {
67 // array of generic type
-
68 auto g2 = g.create_group(name);
-
69 h5_write(g2, "shape", std::array<long, 1>{N});
-
70 for (int i = 0; i < N; ++i) h5_write(g2, std::to_string(i), a[i]);
+
68 auto g2 = g.create_group(name);
+
69 h5_write(g2, "shape", std::array<long, 1>{N});
+
70 for (int i = 0; i < N; ++i) h5_write(g2, std::to_string(i), a[i]);
71 }
72 }
73
-
74 /**
-
75 * @brief Read a std::array from an HDF5 dataset/subgroup.
-
76 *
-
77 * @tparam T Value type of the std::array.
-
78 * @tparam N Size of the std::array.
-
79 * @param g h5::group containing the dataset/subgroup.
-
80 * @param name Name of the dataset/subgroup from which the std::array is read.
-
81 * @param a std::array to read into.
-
82 */
-
83 template <typename T, size_t N>
+
83 template <typename T, size_t N>
-
84 void h5_read(group g, std::string name, std::array<T, N> &a) {
+
84 void h5_read(group g, std::string name, std::array<T, N> &a) {
85 if constexpr (std::is_same_v<T, std::string>) {
86 // array of strings
-
87 auto char_arr = std::array<char *, N>{};
-
88 h5_read(g, name, char_arr);
+
87 auto char_arr = std::array<char *, N>{};
+
88 h5_read(g, name, char_arr);
89 std::copy(cbegin(char_arr), cend(char_arr), begin(a));
90 std::for_each(begin(char_arr), end(char_arr), [](char *cb) { free(cb); }); // NOLINT (we have to free the memory allocated by h5_read)
-
91 } else if constexpr (std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or std::is_same_v<T, char *>
-
92 or std::is_same_v<T, const char *>) {
+
91 } else if constexpr (std::is_arithmetic_v<T> or is_complex_v<T> or std::is_same_v<T, dcplx_t> or std::is_same_v<T, char *>
+
92 or std::is_same_v<T, const char *>) {
93 // array of arithmetic/complex types or char* or const char*
-
94 auto ds_info = array_interface::get_dataset_info(g, name);
-
95 H5_EXPECTS(ds_info.rank() == 1 + ds_info.has_complex_attribute);
-
96 H5_EXPECTS(N == ds_info.lengths[0]);
+
94 auto ds_info = array_interface::get_dataset_info(g, name);
+
95 H5_EXPECTS(ds_info.rank() == 1 + ds_info.has_complex_attribute);
+
96 H5_EXPECTS(N == ds_info.lengths[0]);
97
-
98 if constexpr (is_complex_v<T>) {
+
98 if constexpr (is_complex_v<T>) {
99 // read complex values stored as a compound HDF5 datatype
- -
101 h5_read(g, name, reinterpret_cast<std::array<dcplx_t, N> &>(a)); // NOLINT (reinterpret_cast is safe here)
+
100 if (hdf5_type_equal(ds_info.ty, hdf5_type<dcplx_t>())) {
+
101 h5_read(g, name, reinterpret_cast<std::array<dcplx_t, N> &>(a)); // NOLINT (reinterpret_cast is safe here)
102 return;
103 }
104
105 // read non-complex data into std::array<std::complex>
-
106 if (!ds_info.has_complex_attribute) {
-
107 std::cerr << "WARNING: HDF5 type mismatch while reading into a std::array: std::complex<" + get_name_of_h5_type(hdf5_type<T>())
-
108 + "> != " + get_name_of_h5_type(ds_info.ty) + "\n";
-
109 std::array<double, N> tmp{};
-
110 h5_read(g, name, tmp);
+
106 if (!ds_info.has_complex_attribute) {
+
107 std::cerr << "WARNING: HDF5 type mismatch while reading into a std::array: std::complex<" + get_name_of_h5_type(hdf5_type<T>())
+
108 + "> != " + get_name_of_h5_type(ds_info.ty) + "\n";
+
109 std::array<double, N> tmp{};
+
110 h5_read(g, name, tmp);
111 std::copy(begin(tmp), end(tmp), begin(a));
112 return;
113 }
114 }
115
116 // use array_interface to read
-
117 array_interface::array_view v{hdf5_type<T>(), (void *)(a.data()), 1, is_complex_v<T>};
-
118 v.slab.count[0] = N;
-
119 v.slab.stride[0] = 1;
-
120 v.parent_shape[0] = N;
-
121 array_interface::read(g, name, v);
+
117 array_interface::array_view v{hdf5_type<T>(), (void *)(a.data()), 1, is_complex_v<T>};
+
118 v.slab.count[0] = N;
+
119 v.slab.stride[0] = 1;
+
120 v.parent_shape[0] = N;
+
121 array_interface::read(g, name, v);
122 } else {
123 // array of generic type
-
124 auto g2 = g.open_group(name);
+
124 auto g2 = g.open_group(name);
125
126 // check that shapes are compatible
-
127 auto h5_shape = std::array<long, 1>{};
-
128 h5_read(g2, "shape", h5_shape);
-
129 H5_EXPECTS(N == h5_shape[0]);
+
127 auto h5_shape = std::array<long, 1>{};
+
128 h5_read(g2, "shape", h5_shape);
+
129 H5_EXPECTS(N == h5_shape[0]);
130
131 // read using specialized h5_read implementation
-
132 for (int i = 0; i < N; ++i) h5_read(g2, std::to_string(i), a[i]);
+
132 for (int i = 0; i < N; ++i) h5_read(g2, std::to_string(i), a[i]);
133 }
134 }
135
-
136 /** @} */
-
137
138} // namespace h5
139
-
140#endif // LIBH5_STL_ARRAY_HPP
+
140#endif // LIBH5_STL_ARRAY_HPP
+
Provides a generic interface to read/write n-dimensional arrays from/to HDF5.
A handle to an HDF5 group.
Definition group.hpp:44
group create_group(std::string const &key, bool delete_if_exists=true) const
Create a subgroup with the given key in the group.
Definition group.cpp:109
group open_group(std::string const &key) const
Open a subgroup with the given key in the group.
Definition group.cpp:96
+
Provides a compound type and type traits for complex numbers.
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
Definition object.cpp:198
+
constexpr bool is_complex_v
Boolean type trait set to true for std::complex types.
Definition complex.hpp:64
datatype hdf5_type()
Map a given C++ type to an HDF5 datatype.
Definition object.hpp:156
std::string get_name_of_h5_type(datatype dt)
Get the name of an h5::datatype (for error messages).
Definition object.cpp:183
-
void h5_write(group g, std::string const &name, std::array< T, N > const &a)
Write a std::array to an HDF5 dataset/subgroup.
Definition array.hpp:52
-
void h5_read(group g, std::string name, std::array< T, N > &a)
Read a std::array from an HDF5 dataset/subgroup.
Definition array.hpp:84
void read(group g, std::string const &name, array_view v, hyperslab sl)
Read a given hyperslab from an HDF5 dataset into an array view.
+
dataset_info get_dataset_info(dataset ds)
Retrieve the shape and the h5::datatype from a dataset.
void write(group g, std::string const &name, array_view const &v, bool compress)
Write an array view to an HDF5 dataset.
-
dataset_info get_dataset_info(group g, std::string const &name)
Retrieve the shape and the h5::datatype from a dataset with a given name in the given group.
-
#define H5_EXPECTS(X)
Definition macros.hpp:51
+
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition generic.hpp:51
+
void h5_write(group g, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 dataset.
Definition scalar.hpp:70
+
Macros used in the h5 library.
Struct representing a view on an n-dimensional array/dataspace.
-
v_t parent_shape
Shape of the (contiguous) parent array.
hyperslab slab
h5::array_interface::hyperslab specifying the selection of the view.
-
bool has_complex_attribute
Whether the stored values are complex.
-
datatype ty
h5::datatype stored in the dataset.
-
v_t stride
Stride in each dimension (in the HDF5 sense).
v_t count
Number of elements or blocks to select along each dimension.
-
A complex compound type consisting of two doubles to represent a complex number.
Definition complex.hpp:38
diff --git a/docs/unstable/array__interface_8cpp_source.html b/docs/unstable/array__interface_8cpp_source.html index bb045087..e68eb3da 100644 --- a/docs/unstable/array__interface_8cpp_source.html +++ b/docs/unstable/array__interface_8cpp_source.html @@ -127,41 +127,36 @@
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
-
17/**
-
18 * @file
-
19 * @brief Implementation details for array_interface.hpp.
-
20 */
-
21
-
22#include "./array_interface.hpp"
-
23#include "./macros.hpp"
-
24#include "./stl/string.hpp"
+
22#include "./array_interface.hpp"
+
23#include "./macros.hpp"
+
24#include "./stl/string.hpp"
25
-
26#include <hdf5.h>
-
27#include <hdf5_hl.h>
+
26#include <hdf5.h>
+
27#include <hdf5_hl.h>
28
-
29#include <numeric>
-
30#include <algorithm>
-
31#include <iostream>
-
32#include <stdexcept>
-
33#include <utility>
-
34#include <vector>
+
29#include <numeric>
+
30#include <algorithm>
+
31#include <iostream>
+
32#include <stdexcept>
+
33#include <utility>
+
34#include <vector>
35
-
36namespace h5::array_interface {
+
36namespace h5::array_interface {
37
-
38 namespace {
+
38 namespace {
39
40 // Create an HDF5 memory dataspace.
-
41 dataspace make_mem_dspace(array_view const &v) {
+
41 dataspace make_mem_dspace(array_view const &v) {
42 // scalar case
-
43 if (v.rank() == 0) return H5Screate(H5S_SCALAR);
+
43 if (v.rank() == 0) return H5Screate(H5S_SCALAR);
44
45 // create a dataspace of rank v.rank() and with shape v.parent_shape
-
46 dataspace dspace = H5Screate_simple(v.slab.rank(), v.parent_shape.data(), nullptr);
-
47 if (!dspace.is_valid()) throw std::runtime_error("Error in make_mem_dspace: Creating the dataspace for an array_view failed");
+
46 dataspace dspace = H5Screate_simple(v.slab.rank(), v.parent_shape.data(), nullptr);
+
47 if (!dspace.is_valid()) throw std::runtime_error("Error in make_mem_dspace: Creating the dataspace for an array_view failed");
48
49 // select the hyperslab according to v.slab
-
50 herr_t err = H5Sselect_hyperslab(dspace, H5S_SELECT_SET, v.slab.offset.data(), v.slab.stride.data(), v.slab.count.data(),
-
51 (v.slab.block.empty() ? nullptr : v.slab.block.data()));
+
50 herr_t err = H5Sselect_hyperslab(dspace, H5S_SELECT_SET, v.slab.offset.data(), v.slab.stride.data(), v.slab.count.data(),
+
51 (v.slab.block.empty() ? nullptr : v.slab.block.data()));
52 if (err < 0) throw std::runtime_error("Error in make_mem_dspace: Selecting the hyperslab failed");
53
54 // return the dataspace
@@ -176,7 +171,7 @@
62 if (rank == 0) return {};
63
64 // empty view case: return (0,0,0), (1,1,1)
-
65 if (view_size == 0) return {v_t(rank, 0), v_t(rank, 1)};
+
65 if (view_size == 0) return {v_t(rank, 0), v_t(rank, 1)};
66
67 // for the general case, we would like to find a parent_shape and h5_strides such that the following equations hold (rank = N):
68 // 1. np_strides[N - 1] = h5_strides[N - 1]
@@ -189,14 +184,14 @@
75 // This is not a problem as long as HDF5 manages to select the correct elements in memory.
76
77 // create the result vectors
-
78 v_t parent_shape(rank), h5_strides(rank);
+
78 v_t parent_shape(rank), h5_strides(rank);
79
80 // We initialize the h5_strides array to the values of np_strides
81 // and successively divide off the parent_shape values as they appear
82 // in the equations above.
83 for (int u = 0; u < rank; ++u) h5_strides[u] = np_strides[u];
84 for (int u = rank - 2; u >= 0; --u) {
-
85 hsize_t gcd = h5_strides[u];
+
85 hsize_t gcd = h5_strides[u];
86 for (int v = u - 1; v >= 0; --v) { gcd = std::gcd(gcd, h5_strides[v]); }
87 parent_shape[u + 1] = gcd;
88 for (int v = u; v >= 0; --v) { h5_strides[v] /= gcd; }
@@ -211,122 +206,122 @@
97
- +
99 // retrieve shape and datatype information
-
100 datatype ty = H5Dget_type(ds);
+
100 datatype ty = H5Dget_type(ds);
101 bool has_complex_attribute = H5LTfind_attribute(ds, "__complex__");
-
102 dataspace dspace = H5Dget_space(ds);
+
102 dataspace dspace = H5Dget_space(ds);
103 int rank = H5Sget_simple_extent_ndims(dspace);
-
104 v_t dims_out(rank);
-
105 H5Sget_simple_extent_dims(dspace, dims_out.data(), nullptr);
+
104 v_t dims_out(rank);
+
105 H5Sget_simple_extent_dims(dspace, dims_out.data(), nullptr);
106
107 return {std::move(dims_out), ty, has_complex_attribute};
108 }
109
-
110 dataset_info get_dataset_info(group g, std::string const &name) {
-
111 dataset ds = g.open_dataset(name);
-
112 return get_dataset_info(ds);
+
110 dataset_info get_dataset_info(group g, std::string const &name) {
+
111 dataset ds = g.open_dataset(name);
+
112 return get_dataset_info(ds);
113 }
114
115 void write(group g, std::string const &name, array_view const &v, bool compress) {
116 // unlink the dataset if it already exists
-
117 g.unlink(name);
+
117 g.unlink(name);
118
119 // shape of the hyperslab in memory
-
120 auto hs_shape = v.slab.shape();
+
120 auto hs_shape = v.slab.shape();
121
122 // chunk the dataset and add compression
-
123 proplist cparms = H5P_DEFAULT;
-
124 if (compress and (v.rank() != 0)) {
-
125 int n_dims = v.rank();
+
123 proplist cparms = H5P_DEFAULT;
+
124 if (compress and (v.rank() != 0)) {
+
125 int n_dims = v.rank();
126 std::vector<hsize_t> chunk_dims(n_dims);
-
127 hsize_t const max_chunk_size = hsize_t{1UL << 32} - hsize_t{1}; // 2^32 - 1 = 4 GB
-
128 hsize_t chunk_size = H5Tget_size(v.ty);
-
129 for (int i = v.rank() - 1; i >= 0; --i) {
-
130 H5_ASSERT(max_chunk_size >= chunk_size);
-
131 hsize_t max_dim = max_chunk_size / chunk_size;
-
132 chunk_dims[i] = std::clamp(hs_shape[i], hsize_t{1}, max_dim);
+
127 hsize_t const max_chunk_size = hsize_t{1UL << 32} - hsize_t{1}; // 2^32 - 1 = 4 GB
+
128 hsize_t chunk_size = H5Tget_size(v.ty);
+
129 for (int i = v.rank() - 1; i >= 0; --i) {
+
130 H5_ASSERT(max_chunk_size >= chunk_size);
+
131 hsize_t max_dim = max_chunk_size / chunk_size;
+
132 chunk_dims[i] = std::clamp(hs_shape[i], hsize_t{1}, max_dim);
133 chunk_size *= chunk_dims[i];
134 }
-
135 cparms = H5Pcreate(H5P_DATASET_CREATE);
+
135 cparms = H5Pcreate(H5P_DATASET_CREATE);
136 H5Pset_chunk(cparms, n_dims, chunk_dims.data());
137 H5Pset_deflate(cparms, 1);
138 }
139
140 // dataspace for the dataset in the file
-
141 dataspace file_dspace = H5Screate_simple(v.slab.rank(), hs_shape.data(), nullptr);
+
141 dataspace file_dspace = H5Screate_simple(v.slab.rank(), hs_shape.data(), nullptr);
142
143 // create the dataset in the file
-
144 dataset ds = H5Dcreate2(g, name.c_str(), v.ty, file_dspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
-
145 if (!ds.is_valid())
-
146 throw std::runtime_error("Error in h5::array_interface::write: Creating the dataset " + name + " in the group " + g.name() + " failed");
+
144 dataset ds = H5Dcreate2(g, name.c_str(), v.ty, file_dspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
+
145 if (!ds.is_valid())
+
146 throw std::runtime_error("Error in h5::array_interface::write: Creating the dataset " + name + " in the group " + g.name() + " failed");
147
148 // memory dataspace
-
149 dataspace mem_dspace = make_mem_dspace(v);
+
149 dataspace mem_dspace = make_mem_dspace(v);
150
151 // write to the file dataset
152 if (H5Sget_simple_extent_npoints(mem_dspace) > 0) { // avoid writing empty arrays
-
153 herr_t err = H5Dwrite(ds, v.ty, mem_dspace, H5S_ALL, H5P_DEFAULT, v.start);
+
153 herr_t err = H5Dwrite(ds, v.ty, mem_dspace, H5S_ALL, H5P_DEFAULT, v.start);
154 if (err < 0)
-
155 throw std::runtime_error("Error in h5::array_interface::write: Writing to the dataset " + name + " in the group" + g.name() + " failed");
+
155 throw std::runtime_error("Error in h5::array_interface::write: Writing to the dataset " + name + " in the group" + g.name() + " failed");
156 }
157
158 // add complex attribute if the data is complex valued
-
159 if (v.is_complex) h5_write_attribute(ds, "__complex__", "1");
+
159 if (v.is_complex) h5_write_attribute(ds, "__complex__", "1");
160 }
161
162 void write_slice(group g, std::string const &name, array_view const &v, hyperslab sl) {
163 // empty hyperslab
-
164 if (sl.empty()) return;
+
164 if (sl.empty()) return;
165
166 // check consistency of input
-
167 if (v.slab.size() != sl.size()) throw std::runtime_error("Error in h5::array_interface::write_slice: Incompatible sizes");
+
167 if (v.slab.size() != sl.size()) throw std::runtime_error("Error in h5::array_interface::write_slice: Incompatible sizes");
168
-
169 auto ds_info = get_dataset_info(g, name);
-
170 if (not hdf5_type_equal(v.ty, ds_info.ty))
-
171 throw std::runtime_error("Error in h5::array_interface::write_slice: Incompatible HDF5 types: " + get_name_of_h5_type(v.ty)
-
172 + " != " + get_name_of_h5_type(ds_info.ty));
+
169 auto ds_info = get_dataset_info(g, name);
+
170 if (not hdf5_type_equal(v.ty, ds_info.ty))
+
171 throw std::runtime_error("Error in h5::array_interface::write_slice: Incompatible HDF5 types: " + get_name_of_h5_type(v.ty)
+
172 + " != " + get_name_of_h5_type(ds_info.ty));
173
174 // open existing dataset, get dataspace and select hyperslab
-
175 dataset ds = g.open_dataset(name);
-
176 dataspace file_dspace = H5Dget_space(ds);
-
177 herr_t err = H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, sl.offset.data(), sl.stride.data(), sl.count.data(),
-
178 (sl.block.empty() ? nullptr : sl.block.data()));
+
175 dataset ds = g.open_dataset(name);
+
176 dataspace file_dspace = H5Dget_space(ds);
+
177 herr_t err = H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, sl.offset.data(), sl.stride.data(), sl.count.data(),
+
178 (sl.block.empty() ? nullptr : sl.block.data()));
179 if (err < 0) throw std::runtime_error("Error in h5::array_interface::write_slice: Selecting the hyperslab failed");
180
181 // memory dataspace
-
182 dataspace mem_dspace = make_mem_dspace(v);
+
182 dataspace mem_dspace = make_mem_dspace(v);
183
184 // write to the selected hyperslab of the file dataset
185 if (H5Sget_simple_extent_npoints(file_dspace) > 0) {
-
186 err = H5Dwrite(ds, v.ty, mem_dspace, file_dspace, H5P_DEFAULT, v.start);
+
186 err = H5Dwrite(ds, v.ty, mem_dspace, file_dspace, H5P_DEFAULT, v.start);
187 if (err < 0)
-
188 throw std::runtime_error("Error in h5::array_interface::write_slice: Writing the dataset " + name + " in the group " + g.name() + " failed");
+
188 throw std::runtime_error("Error in h5::array_interface::write_slice: Writing the dataset " + name + " in the group " + g.name() + " failed");
189 }
190 }
191
-
192 void write_attribute(object obj, std::string const &name, array_view v) {
+
192 void write_attribute(object obj, std::string const &name, array_view v) {
193 // check if the attribute already exists
194 if (H5LTfind_attribute(obj, name.c_str()) != 0)
195 throw std::runtime_error("Error in h5::array_interface::write_attribute: Attribute " + name + " already exists");
196
197 // memory dataspace
-
198 dataspace mem_dspace = make_mem_dspace(v);
+
198 dataspace mem_dspace = make_mem_dspace(v);
199
200 // create attribute to write to
-
201 attribute attr = H5Acreate2(obj, name.c_str(), v.ty, mem_dspace, H5P_DEFAULT, H5P_DEFAULT);
-
202 if (!attr.is_valid()) throw std::runtime_error("Error in h5::array_interface::write_attribute: Creating the attribute " + name + " failed");
+
201 attribute attr = H5Acreate2(obj, name.c_str(), v.ty, mem_dspace, H5P_DEFAULT, H5P_DEFAULT);
+
202 if (!attr.is_valid()) throw std::runtime_error("Error in h5::array_interface::write_attribute: Creating the attribute " + name + " failed");
203
204 // write to the attribute
-
205 herr_t err = H5Awrite(attr, v.ty, v.start);
+
205 herr_t err = H5Awrite(attr, v.ty, v.start);
206 if (err < 0) throw std::runtime_error("Error in h5::array_interface::write_attribute: Writing to the attribute " + name + " failed");
207 }
@@ -334,72 +329,73 @@
209 void read(group g, std::string const &name, array_view v, hyperslab sl) {
210 // open dataset and get dataspace
-
211 dataset ds = g.open_dataset(name);
-
212 dataspace file_dspace = H5Dget_space(ds);
+
211 dataset ds = g.open_dataset(name);
+
212 dataspace file_dspace = H5Dget_space(ds);
213
214 // if provided, select the hyperslab of the file dataspace
-
215 if (not sl.empty()) {
-
216 herr_t err = H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, sl.offset.data(), sl.stride.data(), sl.count.data(),
-
217 (sl.block.empty() ? nullptr : sl.block.data()));
+
215 if (not sl.empty()) {
+
216 herr_t err = H5Sselect_hyperslab(file_dspace, H5S_SELECT_SET, sl.offset.data(), sl.stride.data(), sl.count.data(),
+
217 (sl.block.empty() ? nullptr : sl.block.data()));
218 if (err < 0) throw std::runtime_error("Error in h5::array_interface::read: selecting the hyperslab failed");
219 }
220
221 // check consistency of input
-
222 auto ds_info = get_dataset_info(g, name);
-
223 if (H5Tget_class(v.ty) != H5Tget_class(ds_info.ty))
-
224 throw std::runtime_error("Error in h5::array_interface::read: Incompatible HDF5 types: " + get_name_of_h5_type(v.ty)
-
225 + " != " + get_name_of_h5_type(ds_info.ty));
+
222 auto ds_info = get_dataset_info(g, name);
+
223 if (H5Tget_class(v.ty) != H5Tget_class(ds_info.ty))
+
224 throw std::runtime_error("Error in h5::array_interface::read: Incompatible HDF5 types: " + get_name_of_h5_type(v.ty)
+
225 + " != " + get_name_of_h5_type(ds_info.ty));
226
-
227 if (not hdf5_type_equal(v.ty, ds_info.ty))
-
228 std::cerr << "WARNING: HDF5 type mismatch while reading into an array_view: " + get_name_of_h5_type(v.ty)
-
229 + " != " + get_name_of_h5_type(ds_info.ty) + "\n";
+
227 if (not hdf5_type_equal(v.ty, ds_info.ty))
+
228 std::cerr << "WARNING: HDF5 type mismatch while reading into an array_view: " + get_name_of_h5_type(v.ty)
+
229 + " != " + get_name_of_h5_type(ds_info.ty) + "\n";
230
-
231 auto sl_size = sl.size();
-
232 if (sl.empty()) { sl_size = std::accumulate(ds_info.lengths.begin(), ds_info.lengths.end(), (hsize_t)1, std::multiplies<>()); }
-
233 if (sl_size != v.slab.size()) throw std::runtime_error("Error in h5::array_interface::read: Incompatible sizes");
+
231 auto sl_size = sl.size();
+
232 if (sl.empty()) { sl_size = std::accumulate(ds_info.lengths.begin(), ds_info.lengths.end(), (hsize_t)1, std::multiplies<>()); }
+
233 if (sl_size != v.slab.size()) throw std::runtime_error("Error in h5::array_interface::read: Incompatible sizes");
234
235 // memory dataspace
-
236 dataspace mem_dspace = make_mem_dspace(v);
+
236 dataspace mem_dspace = make_mem_dspace(v);
237
238 // read the selected hyperslab from the file dataset
239 if (H5Sget_simple_extent_npoints(file_dspace) > 0) {
-
240 herr_t err = H5Dread(ds, v.ty, mem_dspace, file_dspace, H5P_DEFAULT, v.start);
+
240 herr_t err = H5Dread(ds, v.ty, mem_dspace, file_dspace, H5P_DEFAULT, v.start);
241 if (err < 0)
-
242 throw std::runtime_error("Error in h5::array_interface::read: Reading the dataset " + name + " in the group " + g.name() + " failed");
+
242 throw std::runtime_error("Error in h5::array_interface::read: Reading the dataset " + name + " in the group " + g.name() + " failed");
243 }
244 }
245
-
246 void read_attribute(object obj, std::string const &name, array_view v) {
+
246 void read_attribute(object obj, std::string const &name, array_view v) {
247 // open attribute
-
248 attribute attr = H5Aopen(obj, name.c_str(), H5P_DEFAULT);
-
249 if (!attr.is_valid()) throw std::runtime_error("Error in h5::array_interface::read_attribute: Opening the attribute " + name + " failed");
+
248 attribute attr = H5Aopen(obj, name.c_str(), H5P_DEFAULT);
+
249 if (!attr.is_valid()) throw std::runtime_error("Error in h5::array_interface::read_attribute: Opening the attribute " + name + " failed");
250
251 // get dataspace information
-
252 dataspace space = H5Aget_space(attr);
+
252 dataspace space = H5Aget_space(attr);
253 int rank = H5Sget_simple_extent_ndims(space);
254 if (rank != 0) throw std::runtime_error("Error in h5::array_interface::read_attribute: Attribute " + name + " has a rank != 0");
255
256 // get datatype information
-
257 auto eq = H5Tequal(H5Aget_type(attr), v.ty);
+
257 auto eq = H5Tequal(H5Aget_type(attr), v.ty);
258 if (eq < 0) throw std::runtime_error("Error in h5::array_interface::read_attribute: H5Tequal call failed");
259 if (eq == 0) throw std::runtime_error("Error in h5::array_interface::read_attribute: Incompatible HDF5 types");
260
261 // read the attribute
-
262 auto err = H5Aread(attr, v.ty, v.start);
+
262 auto err = H5Aread(attr, v.ty, v.start);
263 if (err < 0) throw std::runtime_error("Error in h5::array_interface::read_attribute: Reading the attribute " + name + " failed");
264 }
265
266} // namespace h5::array_interface
+
Provides a generic interface to read/write n-dimensional arrays from/to HDF5.
A handle to an HDF5 group.
Definition group.hpp:44
dataset open_dataset(std::string const &key) const
Open a dataset with the given key in the group.
Definition group.cpp:140
std::string name() const
Get the name of the group.
Definition group.cpp:39
void unlink(std::string const &key, bool error_if_absent=false) const
Remove a link with the given key from the group.
Definition group.cpp:83
A generic handle for HDF5 objects.
Definition object.hpp:49
bool is_valid() const
Ensure that the wrapped HDF5 ID is valid (by calling H5Iis_valid).
Definition object.cpp:116
-
object & operator=(object &&x) noexcept
Move assignment operator steals the underlying HDF5 ID without increasing its reference count.
Definition object.cpp:102
+
object dataspace
Type alias for an HDF5 dataspace.
Definition object.hpp:126
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
Definition object.cpp:198
std::string get_name_of_h5_type(datatype dt)
Get the name of an h5::datatype (for error messages).
Definition object.cpp:183
void read_attribute(object obj, std::string const &name, array_view v)
Read from an HDF5 attribute into an array view.
@@ -408,20 +404,19 @@
void write_attribute(object obj, std::string const &name, array_view v)
Write an array view to an HDF5 attribute.
dataset_info get_dataset_info(dataset ds)
Retrieve the shape and the h5::datatype from a dataset.
void write(group g, std::string const &name, array_view const &v, bool compress)
Write an array view to an HDF5 dataset.
-
dataset_info get_dataset_info(group g, std::string const &name)
Retrieve the shape and the h5::datatype from a dataset with a given name in the given group.
std::pair< v_t, v_t > get_parent_shape_and_h5_strides(long const *np_strides, int rank, long view_size)
Given a view on an n-dimensional array (dataspace) by specifying its numpy/nda-style strides and its ...
-
void h5_write_attribute(object obj, std::string const &name, const char *s)
Write a const char* to an HDF5 attribute.
Definition string.hpp:96
-
#define H5_ASSERT(X)
Definition macros.hpp:56
+
void h5_write_attribute(object obj, std::string const &name, T const &x) H5_REQUIRES(std
Write a scalar to an HDF5 attribute.
Definition scalar.hpp:125
+
std::vector< hsize_t > v_t
Vector of h5::hsize_t used throughout the h5 library.
Definition utils.hpp:59
+
unsigned long long hsize_t
Size type used in HDF5.
Definition utils.hpp:55
+
Macros used in the h5 library.
+
Provides functions to read/write std::string, char* and h5::char_buf objects from/to HDF5.
Struct representing a view on an n-dimensional array/dataspace.
void * start
Pointer to the data of the array.
-
v_t parent_shape
Shape of the (contiguous) parent array.
datatype ty
h5::datatype stored in the array.
bool is_complex
Whether the data is complex valued.
int rank() const
Get the rank of the view (including the possible added imaginary dimension).
hyperslab slab
h5::array_interface::hyperslab specifying the selection of the view.
Simple struct to store basic information about an HDF5 dataset.
-
v_t lengths
Shape of the dataspace in the dataset.
-
datatype ty
h5::datatype stored in the dataset.
Struct representing an HDF5 hyperslab.
auto size() const
Get the total number of elements in the hyperslab.
v_t block
Shape of a single block selected from the dataspace.
diff --git a/docs/unstable/array__interface_8hpp_source.html b/docs/unstable/array__interface_8hpp_source.html index ad5e343b..104cebcb 100644 --- a/docs/unstable/array__interface_8hpp_source.html +++ b/docs/unstable/array__interface_8hpp_source.html @@ -127,313 +127,129 @@
14//
15// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
-
17/**
-
18 * @file
-
19 * @brief Provides a generic interface to read/write n-dimensional arrays from/to HDF5.
-
20 */
-
21
-
22#ifndef LIBH5_ARRAY_INTERFACE_HPP
-
23#define LIBH5_ARRAY_INTERFACE_HPP
+
22#ifndef LIBH5_ARRAY_INTERFACE_HPP
+
23#define LIBH5_ARRAY_INTERFACE_HPP
24
-
25#include "./group.hpp"
-
26#include "./object.hpp"
+
25#include "./group.hpp"
+
26#include "./object.hpp"
27
-
28#include <algorithm>
-
29#include <numeric>
-
30#include <string>
-
31#include <utility>
+
28#include <algorithm>
+
29#include <numeric>
+
30#include <string>
+
31#include <utility>
32
-
33namespace h5::array_interface {
+
33namespace h5::array_interface {
34
-
35 /**
-
36 * @addtogroup rw_arrayinterface
-
37 * @{
-
38 */
-
39
-
40 /// Simple struct to store basic information about an HDF5 dataset.
-
41 struct dataset_info {
-
42 /// Shape of the dataspace in the dataset.
- +
41 struct dataset_info {
+
44
-
45 /// h5::datatype stored in the dataset.
-
46 datatype ty;
+
47
-
48 /// Whether the stored values are complex.
50
-
51 /// Get the rank of the dataspace in the dataset.
-
52 [[nodiscard]] int rank() const { return static_cast<int>(lengths.size()); }
+
52 [[nodiscard]] int rank() const { return static_cast<int>(lengths.size()); }
53 };
54
-
55 /**
-
56 * @brief Struct representing an HDF5 hyperslab.
-
57 *
-
58 * @details A hyperslab is used to select elements from an n-dimensional array/dataspace and it is defined
-
59 * by 4 arrays of the same size as the rank of the underlying dataspace
-
60 * (see <a href="https://docs.hdfgroup.org/hdf5/v1_12/group___h5_s.html">HDF5 docs</a>):
-
61 * - `offset`: Origin of the hyperslab in the dataspace.
-
62 * - `stride`: The number of elements to skip between each element or block to be selected. If the stride
-
63 * parameter is set to `NULL`, the stride size defaults to 1 in each dimension.
-
64 * - `count`: The number of elements or blocks to select along each dimension.
-
65 * - `block`: The size of a block selected from the dataspace. If the block parameter is set to `NULL`,
-
66 * the block size defaults to a single element in each dimension, as if the block array was set to all ones.
-
67 *
-
68 * The imaginary part of a complex array/dataspace is treated as just another dimension, i.e. its rank is
-
69 * increased by one.
-
70 *
-
71 * The following example selects every second column in a `7x7` dataspace:
-
72 *
-
73 * @code
-
74 * h5::array_interface::hyperslab slab;
-
75 * slab.offset = {0, 0};
-
76 * slab.stride = {1, 2};
-
77 * slab.count = {7, 4};
-
78 * slab.block = {1, 1};
-
79 * @endcode
-
80 *
-
81 * For a complex valued dataspace, the same example would look like this:
-
82 *
-
83 * @code
-
84 * h5::array_interface::hyperslab slab;
-
85 * slab.offset = {0, 0, 0};
-
86 * slab.stride = {1, 2, 1};
-
87 * slab.count = {7, 4, 2};
-
88 * slab.block = {1, 1, 1};
-
89 * @endcode
-
90 */
-
91 struct hyperslab {
-
92 /// Index offset for each dimension.
-
93 v_t offset;
+
91 struct hyperslab {
+
94
-
95 /// Stride in each dimension (in the HDF5 sense).
-
96 v_t stride;
+
97
-
98 /// Number of elements or blocks to select along each dimension.
-
99 v_t count;
+
100
-
101 /// Shape of a single block selected from the dataspace.
-
102 v_t block;
+
103
-
104 /**
-
105 * @brief Construct a new empty hyperslab for a dataspace of a given rank.
-
106 *
-
107 * @details A complex hyperslab has an additional dimension for the imaginary part. By default, `offset` and
-
108 * `count` are set to zero and `stride` and `block` are set to one. If complex valued, `count.back() = 2`.
-
109 *
-
110 * @param rank Rank of the underlying dataspace (excluding the possible added imaginary dimension).
-
111 * @param is_complex Whether the data is complex valued.
-
112 */
-
113 hyperslab(int rank, bool is_complex)
-
114 : offset(rank + is_complex, 0), stride(rank + is_complex, 1), count(rank + is_complex, 0), block(rank + is_complex, 1) {
+
113 hyperslab(int rank, bool is_complex)
+
114 : offset(rank + is_complex, 0), stride(rank + is_complex, 1), count(rank + is_complex, 0), block(rank + is_complex, 1) {
115 if (is_complex) {
-
116 stride[rank] = 1;
-
117 count[rank] = 2;
+
116 stride[rank] = 1;
+
117 count[rank] = 2;
118 }
119 }
120
-
121 /// Default constructor leaves the hyperslab empty (uninitialized).
122 hyperslab() = default;
123
-
124 /// Get the rank of the hyperslab (including the possible added imaginary dimension).
-
125 [[nodiscard]] int rank() const { return static_cast<int>(count.size()); }
+
125 [[nodiscard]] int rank() const { return static_cast<int>(count.size()); }
126
-
127 /// Check whether the hyperslab is empty (has been initialized).
-
128 [[nodiscard]] bool empty() const { return count.empty(); }
+
128 [[nodiscard]] bool empty() const { return count.empty(); }
129
-
130 /// Get the shape of the selected hyperslab.
-
131 [[nodiscard]] v_t shape() const {
-
132 v_t shape(rank());
-
133 std::transform(count.begin(), count.end(), block.begin(), shape.begin(), std::multiplies<>());
-
134 return shape;
+
131 [[nodiscard]] v_t shape() const {
+
132 v_t shape(rank());
+
133 std::transform(count.begin(), count.end(), block.begin(), shape.begin(), std::multiplies<>());
+
134 return shape;
135 }
136
-
137 /// Get the total number of elements in the hyperslab.
-
138 [[nodiscard]] auto size() const {
-
139 auto sh = shape();
-
140 return std::accumulate(sh.begin(), sh.end(), (hsize_t)1, std::multiplies<>());
+
138 [[nodiscard]] auto size() const {
+
139 auto sh = shape();
+
140 return std::accumulate(sh.begin(), sh.end(), (hsize_t)1, std::multiplies<>());
141 }
142 };
143
-
144 /**
-
145 * @brief Struct representing a view on an n-dimensional array/dataspace.
-
146 *
-
147 * @details A view consists of the parent array and of an h5::array_interface::hyperslab specifying a selection.
-
148 * The parent array is defined by a pointer to its data and its shape.
-
149 *
-
150 * Note that the shape of the parent array does not necessarily have to correspond to the actual shape and size of
-
151 * the underlying memory. It is only used to select the correct elements in the hyperslab.
-
152 *
-
153 * If the data of the array is complex, its imaginary part is treated as just another dimension.
-
154 */
-
155 struct array_view {
-
156 /// h5::datatype stored in the array.
-
157 datatype ty;
+
155 struct array_view {
+
158
-
159 /// Pointer to the data of the array.
160 void *start;
161
-
162 /// Shape of the (contiguous) parent array.
- +
164
-
165 /// h5::array_interface::hyperslab specifying the selection of the view.
167
-
168 /// Whether the data is complex valued.
170
-
171 /**
-
172 * @brief Construct a new empty array view.
-
173 *
-
174 * @details A complex view has an additional dimension for the imaginary part. The shape of the
-
175 * parent array is left uninitialized and the h5::array_interface::hyperslab is empty.
-
176 *
-
177 * @param ty h5::datatype of the array.
-
178 * @param start Pointer to the data of the parent array.
-
179 * @param rank Rank of the parent array (excluding the possible added imaginary dimension).
-
180 * @param is_complex Whether the data is complex valued.
-
181 */
-
182 array_view(datatype ty, void *start, int rank, bool is_complex)
-
183 : ty(std::move(ty)), start(start), parent_shape(rank + is_complex), slab(rank, is_complex), is_complex(is_complex) {
-
184 if (is_complex) parent_shape[rank] = 2;
+ + +
184 if (is_complex) parent_shape[rank] = 2;
185 }
186
-
187 /// Get the rank of the view (including the possible added imaginary dimension).
-
188 [[nodiscard]] int rank() const { return slab.rank(); }
+
188 [[nodiscard]] int rank() const { return slab.rank(); }
189 };
190
-
191 /**
-
192 * @brief Given a view on an n-dimensional array (dataspace) by specifying its numpy/nda-style strides and
-
193 * its size (number of elements in the view), calculate the shape of a possible parent array and the corresponding
-
194 * HDF5 strides of the view.
-
195 *
-
196 * @details The memory layout is assumend to be in C-order. Suppose `parent_shape` is an array containing the shape of
-
197 * the n-dimensional parent array, `np_strides` contains the numpy strides and `h5_strides` are the HDF5 strides. Then
-
198 * the following equations have to hold (rank = N):
-
199 * - `np_strides[N - 1] = h5_strides[N - 1]`
-
200 * - `np_strides[N - 2] = h5_strides[N - 2] * parent_shape[N - 1]`
-
201 * - `np_strides[N - 3] = h5_strides[N - 3] * parent_shape[N - 1] * parent_shape[N - 2]`
-
202 * - `...`
-
203 * - `np_strides[N - N] = h5_strides[N - N] * parent_shape[N - 1] * parent_shape[N - 2] * ... * parent_shape[1]`.
-
204 *
-
205 * @note The shape of the parent array as well as the HDF5 strides that fulfill the above equations are not unique.
-
206 * This is not a problem as long as HDF5 manages to select the correct elements in memory.
-
207 *
-
208 * @param np_strides Numpy/nda-style strides.
-
209 * @param rank Rank of the n-dimensional parent array.
-
210 * @param view_size Number of elements in the given view.
-
211 * @return std::pair containing the shape of the parent array and the HDF5 strides of the view.
-
212 */
213 std::pair<v_t, v_t> get_parent_shape_and_h5_strides(long const *np_strides, int rank, long view_size);
214
-
215 /**
-
216 * @brief Retrieve the shape and the h5::datatype from a dataset.
-
217 *
-
218 * @param ds h5::dataset.
-
219 * @return h5::array_interface::dataset_info containing the shape and HDF5 type of the dataset.
-
220 */
-
221 dataset_info get_dataset_info(dataset ds);
+
221 dataset_info get_dataset_info(dataset ds);
222
-
223 /**
-
224 * @brief Retrieve the shape and the h5::datatype from a dataset with a given name in the given group.
-
225 *
-
226 * @param g h5::group containing the dataset.
-
227 * @param name Name of the dataset.
-
228 * @return h5::array_interface::dataset_info containing the shape and HDF5 type of the dataset.
-
229 */
-
230 dataset_info get_dataset_info(group g, std::string const &name);
+
230 dataset_info get_dataset_info(group g, std::string const &name);
231
-
232 /**
-
233 * @brief Write an array view to an HDF5 dataset.
-
234 *
-
235 * @details If a link with the given name already exists, it is first unlinked.
-
236 *
-
237 * @param g h5::group in which the dataset is created.
-
238 * @param name Name of the dataset
-
239 * @param v h5::array_interface::array_view to be written.
-
240 * @param compress Whether to compress the dataset.
-
241 */
-
242 void write(group g, std::string const &name, array_view const &v, bool compress);
+
242 void write(group g, std::string const &name, array_view const &v, bool compress);
243
-
244 /**
-
245 * @brief Write an array view to a selected hyperslab of an existing HDF5 dataset.
-
246 *
-
247 * @details It checks if the number of elements in the view is the same as selected in the hyperslab and if the
-
248 * datatypes are compatible. Otherwise, an exception is thrown.
-
249 *
-
250 * @param g h5::group which contains the dataset.
-
251 * @param name Name of the dataset.
-
252 * @param v h5::array_interface::array_view to be written.
-
253 * @param sl h5::array_interface::hyperslab specifying the selection to be written to.
-
254 */
-
255 void write_slice(group g, std::string const &name, array_view const &v, hyperslab sl);
+
255 void write_slice(group g, std::string const &name, array_view const &v, hyperslab sl);
256
-
257 /**
-
258 * @brief Write an array view to an HDF5 attribute.
-
259 *
-
260 * @param obj h5::object to which the attribute is attached.
-
261 * @param name Name of the attribute.
-
262 * @param v v h5::array_interface::array_view to be written.
-
263 */
-
264 void write_attribute(object obj, std::string const &name, array_view v);
+
264 void write_attribute(object obj, std::string const &name, array_view v);
265
-
266 /**
-
267 * @brief Read a given hyperslab from an HDF5 dataset into an array view.
-
268 *
-
269 * @param g h5::group which contains the dataset.
-
270 * @param name Name of the dataset.
-
271 * @param v h5::array_interface::array_view to read into.
-
272 * @param sl h5::array_interface::hyperslab specifying the selection to read from.
-
273 */
-
274 void read(group g, std::string const &name, array_view v, hyperslab sl = {});
+
274 void read(group g, std::string const &name, array_view v, hyperslab sl = {});
275
-
276 /**
-
277 * @brief Read from an HDF5 attribute into an array view.
-
278 *
-
279 * @param obj h5::object to which the attribute is attached.
-
280 * @param name Name of the attribute.
-
281 * @param v h5::array_interface::array_view to read into.
-
282 */
-
283 void read_attribute(object obj, std::string const &name, array_view v);
+
283 void read_attribute(object obj, std::string const &name, array_view v);
284
-
285 /** @} */
-
286
287} // namespace h5::array_interface
288
-
289#endif // LIBH5_ARRAY_INTERFACE_HPP
+
289#endif // LIBH5_ARRAY_INTERFACE_HPP
A handle to an HDF5 group.
Definition group.hpp:44
-
dataset open_dataset(std::string const &key) const
Open a dataset with the given key in the group.
Definition group.cpp:140
-
std::string name() const
Get the name of the group.
Definition group.cpp:39
-
void unlink(std::string const &key, bool error_if_absent=false) const
Remove a link with the given key from the group.
Definition group.cpp:83
A generic handle for HDF5 objects.
Definition object.hpp:49
-
object(object &&x) noexcept
Move constructor steals the underlying HDF5 ID without increasing its reference count.
Definition object.hpp:83
-
bool is_valid() const
Ensure that the wrapped HDF5 ID is valid (by calling H5Iis_valid).
Definition object.cpp:116
-
object & operator=(object &&x) noexcept
Move assignment operator steals the underlying HDF5 ID without increasing its reference count.
Definition object.cpp:102
-
bool hdf5_type_equal(datatype dt1, datatype dt2)
Check if two HDF5 datatypes are equal.
Definition object.cpp:198
-
std::string get_name_of_h5_type(datatype dt)
Get the name of an h5::datatype (for error messages).
Definition object.cpp:183
+
Provides a handle to an HDF5 group and various methods to simplify the creation/opening of subgroups,...
void read_attribute(object obj, std::string const &name, array_view v)
Read from an HDF5 attribute into an array view.
void write_slice(group g, std::string const &name, array_view const &v, hyperslab sl)
Write an array view to a selected hyperslab of an existing HDF5 dataset.
void read(group g, std::string const &name, array_view v, hyperslab sl)
Read a given hyperslab from an HDF5 dataset into an array view.
void write_attribute(object obj, std::string const &name, array_view v)
Write an array view to an HDF5 attribute.
dataset_info get_dataset_info(dataset ds)
Retrieve the shape and the h5::datatype from a dataset.
void write(group g, std::string const &name, array_view const &v, bool compress)
Write an array view to an HDF5 dataset.
-
dataset_info get_dataset_info(group g, std::string const &name)
Retrieve the shape and the h5::datatype from a dataset with a given name in the given group.
std::pair< v_t, v_t > get_parent_shape_and_h5_strides(long const *np_strides, int rank, long view_size)
Given a view on an n-dimensional array (dataspace) by specifying its numpy/nda-style strides and its ...
-
void h5_write_attribute(object obj, std::string const &name, const char *s)
Write a const char* to an HDF5 attribute.
Definition string.hpp:96
-
#define H5_ASSERT(X)
Definition macros.hpp:56
+
std::vector< hsize_t > v_t
Vector of h5::hsize_t used throughout the h5 library.
Definition utils.hpp:59
+
unsigned long long hsize_t
Size type used in HDF5.
Definition utils.hpp:55
+
Provides a generic handle for HDF5 objects.
Struct representing a view on an n-dimensional array/dataspace.
void * start
Pointer to the data of the array.
array_view(datatype ty, void *start, int rank, bool is_complex)
Construct a new empty array view.
diff --git a/docs/unstable/changelog.html b/docs/unstable/changelog.html index 0b008d41..7e73b512 100644 --- a/docs/unstable/changelog.html +++ b/docs/unstable/changelog.html @@ -158,7 +158,7 @@