TRIQS/nda 1.3.0
Multi-dimensional array library for C++
|
HDF5 support for nda::basic_array and nda::basic_array_view objects.
nda uses the TRIQS/h5 library to provide functions to write (nda::h5_write) and read (nda::h5_read) arrays and views to and from HDF5 files.
The following example demonstrates some of these features:
Dumping the content of "A.h5":
Functions | |
template<MemoryArray A, typename... IRs> | |
void | nda::h5_read (h5::group g, std::string const &name, A &a, std::tuple< IRs... > const &slice={}) |
Read into an nda::MemoryArray from an HDF5 file. | |
template<MemoryArray A> | |
void | nda::h5_write (h5::group g, std::string const &name, A const &a, bool compress=true) |
Write an nda::MemoryArray to a new dataset/subgroup into an HDF5 file. | |
template<MemoryArray A, typename... IRs> | |
void | nda::h5_write (h5::group g, std::string const &name, A const &a, std::tuple< IRs... > const &slice) |
Write an nda::MemoryArray into a slice (hyperslab) of an existing dataset in an HDF5 file. | |
template<size_t NDim, typename... IRs> | |
auto | nda::hyperslab_and_shape_from_slice (std::tuple< IRs... > const &slice, std::vector< h5::hsize_t > const &ds_shape, bool is_complex) |
Construct an h5::array_interface::hyperslab and the corresponding shape from a given slice, i.e. a tuple containing integer, nda::range , nda::range::all_t and nda::ellipsis objects. | |
void nda::h5_read | ( | h5::group | g, |
std::string const & | name, | ||
A & | a, | ||
std::tuple< IRs... > const & | slice = {} ) |
#include <nda/h5.hpp>
Read into an nda::MemoryArray from an HDF5 file.
The following arrays/views are supported:
h5::char_buf
and then copied into the array/view.h5::dataset
into the array/view. If the stride order is not C-order, the data is first read into an array with C-order layout, before it is copied into the array/view. The data to be read from the dataset can be restricted by providing a slice.A | nda::MemoryArray type. |
IRs | Types in the slice, i.e. integer, nda::range , nda::range::all_t or nda::ellipsis. |
g | h5::group which contains the dataset/subgroup to read from. |
name | Name of the dataset/subgroup. |
a | nda::MemoryArray object to be read into. |
slice | Optional tuple specifying the slice of the dataset to be read. |
void nda::h5_write | ( | h5::group | g, |
std::string const & | name, | ||
A const & | a, | ||
bool | compress = true ) |
#include <nda/h5.hpp>
Write an nda::MemoryArray to a new dataset/subgroup into an HDF5 file.
The following arrays/views can be written to HDF5:
h5::char_buf
before it is written.h5::dataset
with the same shape. If the stride order is not C-order, the elements of the array/view are first copied into an array with C-order layout.A | nda::MemoryArray type. |
g | h5::group in which the dataset/subgroup is created. |
name | Name of the dataset/subgroup to which the nda::MemoryArray is written. |
a | nda::MemoryArray to be written. |
compress | Whether to compress the dataset. |
void nda::h5_write | ( | h5::group | g, |
std::string const & | name, | ||
A const & | a, | ||
std::tuple< IRs... > const & | slice ) |
#include <nda/h5.hpp>
Write an nda::MemoryArray into a slice (hyperslab) of an existing dataset in an HDF5 file.
The hyperslab in the dataset is specified by providing a tuple of integer, nda::range
, nda::range::all_t
or nda::ellipsis objects. It's shape must match the shape of the nda::MemoryArray to be written, otherwise an exception is thrown.
Only arrays/views with scalar types can be written to a slice.
A | nda::MemoryArray type. |
IRs | Types in the slice, i.e. integer, nda::range , nda::range::all_t or nda::ellipsis. |
g | h5::group which contains the dataset. |
name | Name of the dataset. |
a | nda::MemoryArray to be written. |
slice | Tuple specifying the slice of the dataset to which the nda::MemoryArray is written. |
auto nda::hyperslab_and_shape_from_slice | ( | std::tuple< IRs... > const & | slice, |
std::vector< h5::hsize_t > const & | ds_shape, | ||
bool | is_complex ) |
#include <nda/h5.hpp>
Construct an h5::array_interface::hyperslab
and the corresponding shape from a given slice, i.e. a tuple containing integer, nda::range
, nda::range::all_t
and nda::ellipsis objects.
The hyperslab will have the same number of dimensions as the underlying dataspace, whereas the shape will only contain the selected dimensions. For example, a 1-dimensional slice of a 3-dimensional dataset will return a hyperslab with 3 dimensions and a shape with 1 dimension.
NDim | Number of selected dimensions (== Rank of the array/view to be written/read into). |
IRs | Types in the slice, i.e. integer, nda::range , nda::range::all_t or nda::ellipsis. |
slice | Tuple specifying the slice of the dataset to which the nda::MemoryArray is written. |
ds_shape | Shape of the underlying dataset. |
is_complex | Whether the data is complex valued. |