H5CPP  v1.14.0
Modern C++ templates for HDF5 serial and parallel I/O
Loading...
Searching...
No Matches
HDF5 datasets

Detailed Description

Templated dataset I/O — h5::create, h5::open, h5::read, h5::write, packet-table streaming (h5::append / h5::flush / h5::reset), and the sparse-matrix CSC group form. Element type T follows the Supported Types dispatch matrix; offset / stride / count / block select hyperslabs; chunking, compression, and access tuning go through the property-list family.

See also
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI

Function Documentation

◆ create() [1/2]

template<class T, class... args_t>
h5::ds_t h5::create ( const h5::fd_t fd,
const std::string dataset_path,
args_t&&...  args 
)
inline

creates a dataset within an already opened HDF5 container By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of const ref& or const T* object being saved/memory region pointed to, the arguments are optional. By default the arguments are set to sensible values, and in most cases the function call will deliver good performance. With that in mind, the options below provide an easy to use high level fine tuning mechanism to get the best experience without calling HDF5 CAPI functions directly.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • dcpldataset creation property list
  • lcpllink creation property list
    example:
    auto ds = h5::create<short>("file.h5","path/to/dataset",
    h5::current_dims{10,20}, h5::max_dims{10,H5S_UNLIMITED},
    h5::create_path | h5::utf8, // optional lcpl with this default settings**
    h5::chunk{2,3} | h5::fill_value<short>{42} | h5::fletcher32 | h5::shuffle | h5::nbit | h5::gzip{9})
    T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
    Read an attribute by name and return its value as type T.
    Definition H5Aread.hpp:76

◆ create() [2/2]

template<class T, class... args_t>
h5::ds_t h5::create ( const std::string file_path,
const std::string dataset_path,
args_t&&...  args 
)
inline

creates a dataset within an HDF5 container opened with flag H5F_ACC_RDWR By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block

Parameters
file_pathpath to the HDF5 container within the OS file system
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of const ref& or const T* object being saved/memory region pointed to, the arguments are optional. By default the arguments are set to sensible values, and in most cases the function call will deliver good performance. With that in mind, the options below provide an easy to use high level fine tuning mechanism to get the best experience without calling HDF5 CAPI functions directly.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • dcpldataset creation property list
  • lcpllink creation property list
    example:
    auto ds = h5::create<short>("file.h5","path/to/dataset",
    h5::current_dims{10,20}, h5::max_dims{10,H5S_UNLIMITED},
    h5::create_path | h5::utf8, // optional lcpl with this default settings**
    h5::chunk{2,3} | h5::fill_value<short>{42} | h5::fletcher32 | h5::shuffle | h5::nbit | h5::gzip{9})

◆ read() [1/10]

template<class T, class... args_t>
std::enable_if_t<!std::is_same_v< T, char ** >, void > h5::read ( const h5::ds_t ds,
T ptr,
args_t&&...  args 
)
inline

Read elements from an open HDF5 dataset into caller-allocated memory.

Low-level raw-pointer overload — caller owns the memory and must supply h5::count{...} so the dispatch knows how many elements to materialise. Optional h5::offset / h5::stride / h5::block select a hyperslab; without them the read covers the whole extent (provided count matches it). For container / value targets use the h5::read(ds, T& ref, ...) overload below, which derives the element count from the destination object.

Parameters
dsvalid open h5::ds_t dataset descriptor
ptrpointer to a memory region large enough to receive all requested elements
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::dataset::readon H5Dread failure (type-conversion error, rank mismatch, invalid hyperslab).


example:

h5::ds_t ds = h5::open(fd, "/grid/data"); // 10x10 float dataset
std::vector<float> buf(10*10);
h5::read(ds, buf.data(), h5::count{10,10}); // whole extent
h5::read(ds, buf.data(), h5::count{4,4}, h5::offset{5,0}); // hyperslab
h5::at_t open(const hid_t &parent, const std::string &path, const h5::acpl_t &acpl=h5::default_acpl)
Open an existing attribute by name on a parent HDF5 object.
Definition H5Aopen.hpp:56
std::enable_if_t<!std::is_same_v< T, char ** >, void > read(const h5::ds_t &ds, T *ptr, args_t &&... args)
Read elements from an open HDF5 dataset into caller-allocated memory.
Definition H5Dread.hpp:56
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write h5::create Supported Types
Examples
collective.cpp, independent.cpp, nested.cpp, smart_ptr.cpp, strings.cpp, throughput.cpp, and tuples_pairs.cpp.

◆ read() [2/10]

template<class T, class... args_t, class = std::enable_if_t<arg::tpos<const h5::count_t&, const args_t&...>::present>>
void h5::read ( const h5::fd_t fd,
const std::string dataset_path,
T ptr,
args_t&&...  args 
)
inline

Open a dataset by path and read elements into caller-allocated memory.

Convenience overload — opens the dataset internally then forwards to h5::read(ds, ptr, ...). The dataset handle is closed via RAII before this function returns. Requires an explicit h5::count{...} (SFINAE-gated): a bare read(fd, path, buf) without count does NOT match here and is dispatched to the by-reference overload instead — that path lets char[N] reach the fixed-length-string branch.

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
ptrpointer to a memory region large enough to receive all requested elements
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.


example:

h5::fd_t fd = h5::open("myfile.h5", H5F_ACC_RDWR);
std::vector<float> buf(10*10);
h5::read(fd, "/path/to/dataset", buf.data(),
h5::count{10,10}, h5::offset{5,0});
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write h5::create

◆ read() [3/10]

template<class T, class... args_t>
void h5::read ( const std::string file_path,
const std::string dataset_path,
T ptr,
args_t&&...  args 
)
inline

Open a file and dataset by path then read into caller-allocated memory.

Convenience overload — opens the file in H5F_ACC_RDWR mode and forwards to h5::read(fd, dataset_path, ptr, ...). Both the file and dataset handles close via RAII before this function returns.

Parameters
file_pathpath to the HDF5 container within the OS file system
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
ptrpointer to a memory region large enough to receive all requested elements
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::file::openif the file cannot be opened.
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write

◆ read() [4/10]

template<class T, class... args_t>
void h5::read ( const h5::ds_t ds,
T ref,
args_t&&...  args 
)
inline

Read into a caller-allocated container or value of type T.

Primary by-reference overload — T is anything the dispatch accepts (see Supported Types): elementary scalar, registered compound POD, fixed or variable-length string, STL container, linear-algebra container, std::tuple / std::pair / std::complex. Element count is derived from ref via access_traits_t<T>::size; passing h5::count{...} here is a compile-time error.

Optional h5::offset / h5::stride / h5::block arguments select a hyperslab from the file space; omitting them reads the whole extent. The on-disk type must be compatible with T — HDF5 has no fixed-length / VLEN string conversion, so a fixed-length string dataset reads into char[N] / std::array<char,N> but not into std::string (and vice versa).

Parameters
dsvalid open h5::ds_t dataset descriptor
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::dataset::readon H5Dread failure (type-conversion error, rank mismatch, etc.).


example:

h5::ds_t ds = h5::open(fd, "/grid/data");
h5::read(ds, v); // whole extent
arma::Mat<double> mat(10, 10);
h5::read(ds, mat, h5::offset{5,0}); // hyperslab
h5::read(ds, label); // VLEN string
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write h5::create Supported Types

◆ read() [5/10]

template<class T, class... args_t, class = std::enable_if_t<!h5::meta::is_sparse_v<std::decay_t<T>>>>
void h5::read ( const h5::fd_t fd,
const std::string dataset_path,
T ref,
args_t&&...  args 
)

Open a dataset by path and read into a caller-allocated container or value.

Convenience overload — opens the dataset then forwards to h5::read(ds, ref, ...). For scatter-decomposed types (compiler- emitted via H5CPP_REGISTER_STRUCT with deep nesting) routes through the generated h5::gather<T> specialization instead.

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write

◆ read() [6/10]

template<class T, class... args_t, class = std::enable_if_t<!h5::meta::is_sparse_v<std::decay_t<T>>>>
void h5::read ( const std::string file_path,
const std::string dataset_path,
T ref,
args_t&&...  args 
)

Open a file and dataset by path then read into a caller-allocated container.

Convenience overload — opens the file in H5F_ACC_RDWR mode and forwards to h5::read(fd, dataset_path, ref, ...).

Parameters
file_pathpath to the HDF5 container within the OS file system
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
void — errors are reported by throwing h5::error derived exceptions
Exceptions
h5::error::io::file::openif the file cannot be opened.
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write

◆ read() [7/10]

template<class T, class... args_t>
T h5::read ( const h5::ds_t ds,
args_t&&...  args 
)
inline

Return-by-value read — materialise the dataset as a fresh T.

The most convenient form — T is constructed in-place from the dataset's shape and populated in one call. Use this when you don't already have a target container; use the by-reference overload (h5::read(ds, T& ref, ...)) when you do.

Optional h5::offset / h5::stride / h5::count / h5::block select a hyperslab; omitting them returns the whole extent.

Parameters
dsvalid open h5::ds_t dataset descriptor
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
fully constructed object of type T populated with dataset data; throws h5::error on failure
Exceptions
h5::error::io::dataset::readon H5Dread failure.


example:

h5::ds_t ds = h5::open(fd, "/grid/data");
auto v = h5::read<std::vector<float>>(ds); // full extent
auto mat = h5::read<arma::Mat<double>>(fd, "/grid/data", // hyperslab
h5::count{10,10}, h5::offset{5,0});
auto lbl = h5::read<std::string>(ds); // VLEN string
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write h5::create Supported Types

◆ read() [8/10]

template<class T, class... args_t, class = std::enable_if_t<!h5::meta::is_sparse_v<std::decay_t<T>>>>
T h5::read ( hid_t  fd,
const std::string dataset_path,
args_t&&...  args 
)
inline

Open a dataset by path and return its contents as a fresh T.

Convenience overload — opens the dataset then forwards to h5::read<T>(ds, ...). Most concise form when both the file and a one-shot read are needed in a single line.

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
fully constructed object of type T populated with dataset data; throws h5::error on failure
Exceptions
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write

◆ read() [9/10]

template<class T, class... args_t, class = std::enable_if_t<!h5::meta::is_sparse_v<std::decay_t<T>>>>
T h5::read ( const std::string file_path,
const std::string dataset_path,
args_t&&...  args 
)
inline

Open a file + dataset by path and return contents as a fresh T.

Most concise convenience form — opens the file in H5F_ACC_RDWR mode, opens the dataset, performs the read, and returns the value all in one line. All intermediate handles close via RAII.

Parameters
file_pathpath to the HDF5 container within the OS file system
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
Returns
fully constructed object of type T populated with dataset data; throws h5::error on failure
Exceptions
h5::error::io::file::openif the file cannot be opened.
h5::error::io::dataset::openif the dataset is not present.
h5::error::io::dataset::readon H5Dread failure.


example:

auto v = h5::read<std::vector<float>>("myfile.h5", "/path/to/dataset");
auto m = h5::read<arma::Mat<double>>("myfile.h5", "/path/to/dataset",
h5::count{10,10}, h5::offset{5,0});
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::open h5::write

◆ write() [1/7]

template<class T, class LOC, class = std::enable_if_t<h5::impl::is_valid_group_parent<LOC>::value && h5::meta::is_sparse_v<T>>>
h5::gr_t h5::write ( const LOC parent,
const std::string path,
const T src 
)
inline

Write a sparse matrix or vector as a CSC group.

Emits the canonical Compressed Sparse Column layout (see Supported Linear Algebra Types § Sparse storage layout) — a group containing four datasets (data, indices, indptr, shape) plus @format = "csc" and @axis = "column" self-describing attributes. The on-disk file is byte-compatible with scipy.sparse.csc_matrix, Julia HDF5.jl, and the 10x Genomics / Loompy convention.

Index width is fixed uint32 on disk regardless of the upstream library's index type; values exceeding 2^32 - 1 throw h5::error::io::dataset::write at the call site.

SFINAE-gated on is_sparse_v<T> so this overload activates only for sparse types; the dense h5::write(fd, path, ref) path excludes them.

Preconditions (the call does not enforce these implicitly — would require a mutable const &):

  • arma::SpMat: SpMat::sync() must have completed.
  • Eigen::SparseMatrix: makeCompressed() must have been called, and the matrix must be ColMajor (RowMajor triggers a compile-time static_assert).
Parameters
parentopen parent handle: h5::fd_t, h5::gr_t, or any handle satisfying is_valid_group_parent<LOC>.
pathPOSIX-style group path; the group is created.
srcsparse source — arma::SpMat / SpRow / SpCol or Eigen::SparseMatrix / SparseVector (ColMajor).
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
LOCdeduced from the parent argument.
Returns
h5::gr_t RAII handle owning the newly created CSC group.
Exceptions
h5::error::io::dataset::writeon H5Dwrite failure or when nnz / n_rows / n_cols exceeds 2^32 - 1.


example:

arma::SpMat<double> A(100, 100);
// ... populate A ...
A.sync(); // precondition for the direct-access traits
h5::write(fd, "/A", A); // CSC group at /A
h5::at_t create(const hid_t &parent, const std::string &path, args_t &&... args)
Create a new attribute of element type T on a parent HDF5 object.
Definition H5Acreate.hpp:100
h5::gr_t write(const LOC &parent, const std::string &path, const T &src)
Write a sparse matrix or vector as a CSC group.
Definition H5Dsparse.hpp:185
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::read Supported Linear Algebra Types
Examples
arma.cpp, attributes.cpp, basics.cpp, blaze.cpp, blitz.cpp, collective.cpp, compound.cpp, container.cpp, cout.cpp, datasets.cpp, datatypes.cpp, detected.cpp, dlib.cpp, eigen.cpp, eigen3.cpp, file_per_rank.cpp, independent.cpp, itpp.cpp, maps.cpp, mdspan.cpp, nested.cpp, optimized.cpp, pipeline.cpp, reference.cpp, reflection.cpp, sequences.cpp, sets.cpp, smart_ptr.cpp, string.cpp, strings.cpp, throughput.cpp, transform.cpp, tuples_pairs.cpp, ublas.cpp, and utf.cpp.

◆ read() [10/10]

template<class T, class LOC, class = std::enable_if_t<h5::impl::is_valid_group_parent<LOC>::value && h5::meta::is_sparse_v<T>>>
T h5::read ( const LOC parent,
const std::string path 
)
inline

Read a CSC group back into a sparse matrix or vector of type T.

Counterpart to h5::write(parent, path, sparse_src). Validates @format = "csc" on the group, reads data / indices / indptr / shape, and reconstructs T via its sparse_traits<T>::construct factory.

Sparse vectors are stored as Nx1 / 1xN CSC matrices on disk; reading into arma::SpCol / SpRow / Eigen::SparseVector materialises the single-column form directly. Reading into arma::SpMat / Eigen::SparseMatrix always works because every sparse value is a matrix on disk.

SFINAE-gated on is_sparse_v<T> so this overload activates only for sparse types.

Parameters
parentopen parent handle holding the CSC group.
pathPOSIX-style path to the CSC group.
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.
LOCdeduced from the parent argument.
Returns
fully constructed sparse object of type T.
Exceptions
h5::error::io::dataset::readon H5Dread / H5Aread failure, wrong @format, or shape mismatch.


example:

// also valid: Eigen::SparseMatrix<double> equivalents,
// and SpRow / SpCol from the same N x 1 / 1 x N storage.
See also
h5::open h5::read h5::write h5::fd_t h5::ds_t h5::err_t
H5Fcreate H5Fopen H5Fclose H5Dopen H5Dclose gzip CAPI
h5::write Supported Linear Algebra Types

◆ write() [2/7]

template<class T >
void h5::write ( const h5::ds_t ds,
const h5::sp_t mem_space,
const h5::sp_t file_space,
const h5::dxpl_t dxpl,
const T ptr 
)
inline

write the memory content of const T* ptr with given mem_space into file_space of the dataset

Parameters
dsvalid open h5::ds_t dataset descriptor
mem_spacethe dimensions of the memory region being transferred
file_spacethe dimensions of the target dataset region nelems(mem_space) == nelems(file_space)
dxpldata transfer property list (h5::dxpl_t)
ptrpointer to a memory region large enough to receive all requested elements
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.

◆ write() [3/7]

template<class T, class... args_t>
h5::ds_t h5::write ( const h5::ds_t ds,
const T ptr,
args_t&&...  args 
)
inline

writes data, from contiguous memory region into an existing, opened dataset specified byh5::ds_t descriptor Lower level template with generative programming paradigm constructs an optimal function respec to specified arguments

Parameters
dsvalid open h5::ds_t dataset descriptor
ptrpointer to a memory region large enough to receive all requested elements
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of const T* pointing to the memory region being saved, the arguments are optional. By default the arguments are set to sensible values, and in most cases the function call will deliver good performance. With that in mind, the options below provide an easy high level fine tuning mechanism to get the best experience without calling HDF5 CAPI functions directly.

  • count — number of blocks selected in each dimension; combined with block gives the total selection shape in hyperslab selection; instead from this value the correct slab_count is derived considering the block size whenever applicable with a normalisation step: slab_count[i] = h5::count[i] / h5::block[i]
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • dcpldataset creation property list
  • dxpldata transfer property list


example:

std::vector<int> data = ...
//creates an extendable, chunked dataset, with initial size matching of the vector
h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR);
h5::ds_t ds = h5::write(fd, "path/chunked layout dataset", data,
h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} | h5::gzip{9});
//creates a contiguous layout dataset, with size matching `data`
h5::ds_t ds = h5::write(fd, "path/contiguous layout dataset", data);
//interop with HDF5 CAPI: will flush dataset `ds` by directly calling libhdf5 function
H5Dflush(ds);

◆ write() [4/7]

template<class T, class... args_t, class = std::enable_if_t<!std::is_pointer_v<std::decay_t<T>> || std::is_array_v<T>>>
h5::ds_t h5::write ( const h5::ds_t ds,
const T ref,
args_t&&...  args 
)
inline

writes data within an HDF5 container specified with h5::fd_t descriptor By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block
This template specialization acts as a switchboard between objects with contiguous content, such as std::vector<int> and objects where the actual content maybe scattered in memory. In the altter case with the help of h5::gather operator, and O(n) complexity this template builds a vector of pointers to actual content, and delegates it to h5::write<element_t*>(.., ptr**) call.

Parameters
dsvalid open h5::ds_t dataset descriptor
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of const ref& object being saved, the arguments are optional. By default the arguments are set to sensible values, and in most cases the function call will deliver good performance. With that in mind, the options below provide an easy high level fine tuning mechanism to get the best experience without calling HDF5 CAPI functions directly.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • count — number of blocks selected in each dimension; combined with block gives the total selection shape in hyperslab selection; instead from this value the correct slab_count is derived considering the block size whenever applicable with a normalisation step: slab_count[i] = h5::count[i] / h5::block[i]
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • dcpldataset creation property list
  • dxpldata transfer property list
  • dapldataset access property list
  • lcpllink creation property list


example:

std::vector<int> data = ...
//creates an extendable, chunked dataset, with initial size matching of the vector
h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR);
h5::ds_t ds = h5::write(fd, "path/chunked layout dataset", data,
h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} | h5::gzip{9});
//creates a contiguous layout dataset, with size matching `data`
h5::ds_t ds = h5::write(fd, "path/contiguous layout dataset", data);
//interop with HDF5 CAPI: will flush dataset `ds` by directly calling libhdf5 function
H5Dflush(ds);

◆ write() [5/7]

template<std::size_t N, class... args_t>
h5::ds_t h5::write ( const h5::fd_t fd,
const std::string dataset_path,
const char(&)  ref[N],
args_t&&...  args 
)
inline

writes data within an HDF5 container specified with h5::fd_t descriptor HDF5 dataset may or may not exist, in first case it is opened and in the latter created. The implemantation comes with sensible default arguments, which can be tuned with optional property list. By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of T object being saved, the arguments are optional. The arguments are set to sensible values, and in most cases will provide good performance by default, with that in mind, it is an easy high level fine tuning mechanism to get the best experience witout trading readability.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • count — number of blocks selected in each dimension; combined with block gives the total selection shape in hyperslab selection; instead from this value the correct slab_count is derived considering the block size whenever applicable with a normalisation step: slab_count[i] = h5::count[i] / h5::block[i]
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • dcpldataset creation property list
  • dxpldata transfer property list
  • dapldataset access property list
  • lcpllink creation property list


example:

h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR);
// dataset will be created with the dimensions specified
h5::ds_t ds = h5::write(fd, "path/dataset from direct memory", object.data(),
h5::current_dims{vec.length()}, h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} | h5::gzip{9});

◆ write() [6/7]

template<class T, class... args_t, class = std::enable_if_t<!std::is_pointer_v<std::decay_t<T>> && !h5::meta::is_sparse_v<std::decay_t<T>>>>
h5::ds_t h5::write ( const h5::fd_t fd,
const std::string dataset_path,
const T ref,
args_t&&...  args 
)
inline

writes data within an HDF5 container specified with h5::fd_t descriptor HDF5 dataset may or may not exist, in first case it is opened and in the latter created. The implemantation comes with sensible default arguments, which can be tuned with optional property list. By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block

Parameters
fdvalid open h5::fd_t file descriptor
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
refreference to a linear algebra object (armadillo, eigen, blitz, blaze, dlib, ublas) or std::vector<T>
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of T object being saved, the arguments are optional. The arguments are set to sensible values, and in most cases will provide good performance by default, with that in mind, it is an easy high level fine tuning mechanism to get the best experience witout trading readability.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • count — number of blocks selected in each dimension; combined with block gives the total selection shape in hyperslab selection; instead from this value the correct slab_count is derived considering the block size whenever applicable with a normalisation step: slab_count[i] = h5::count[i] / h5::block[i]
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • dcpldataset creation property list
  • dxpldata transfer property list
  • dapldataset access property list
  • lcpllink creation property list


example:

h5::fd_t fd = h5::open("example.h5", H5F_ACC_RDWR);
// dataset will be created with the dimensions specified
h5::ds_t ds = h5::write(fd, "path/dataset from direct memory", object.data(),
h5::current_dims{vec.length()}, h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} | h5::gzip{9});

◆ write() [7/7]

template<class... args_t>
h5::ds_t h5::write ( const std::string file_path,
const std::string dataset_path,
args_t&&...  args 
)
inline

writes content of an object, collection of object or memory location to a possibly not yet existing dataset within an HDF5 container opened with flag H5F_ACC_RDWR By default the HDF5 dataset size, the file space, is derived from the passed object properties, or may be explicitly specified with optional properties such as h5::count, h5::current_dims h5::max_dims, h5::stride, h5::block

Parameters
file_pathpath to the HDF5 container within the OS file system
dataset_pathlocation of the dataset within the HDF5 container (absolute or relative POSIX-style path)
args[,...]comma-separated list of arguments in arbitrary order; only T object (or const T* for pointer overloads) is required — the rest (offset, stride, count, block, dxpl, current_dims, max_dims, dcpl, lcpl, …) are context-sensitive optionals
Returns
open h5::ds_t dataset descriptor; throws h5::error on failure
Template Parameters
Tany of the Supported Types — elementary scalar, string, registered compound, STL container (sequence / associative / array-of), dense or sparse linalg container, mdspan view, or reference handle. Resolves to a storage_representation_t at compile time; the dispatch picks the matching read / write path.


The following arguments are context sensitive, may be passed in arbitrary order and with the exception of const ref& or const T* object being saved/memory region pointed to, the arguments are optional. By default the arguments are set to sensible values, and in most cases the function call will deliver good performance. With that in mind, the options below provide an easy to use high level fine tuning mechanism to get the best experience without calling HDF5 CAPI functions directly.

  • current_dims — initial (current) dataset extent When omitted, the system computes the default value as follows h5::block{..} and h5::stride{..} given as: current_dims[i] = count[i] (stride[i] - block[i] + 1) + offset[i] and when only h5::count is available current_dims[i] = count[i] + offset[i]
  • max_dims — maximum dataset extent; use H5S_UNLIMITED to mark an extendable dimension or H5S_UNLIMITED along the dimension intended to be extendable
  • count — number of blocks selected in each dimension; combined with block gives the total selection shape in hyperslab selection; instead from this value the correct slab_count is derived considering the block size whenever applicable with a normalisation step: slab_count[i] = h5::count[i] / h5::block[i]
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • stride — step between selected elements in each dimension; defaults to {1,1,...} (every element)
  • block — size of each selected block in each dimension; defaults to {1,1,...} (single elements)
  • offset — coordinates of the first element selected in file space; one value per dataset dimension (e.g. h5::offset{0,0,0} for rank-3)
  • dcpldataset creation property list
  • dxpldata transfer property list
  • dapldataset access property list
  • lcpllink creation property list
    example:
    std::vector<int> data = ...
    //creates an extendable, chunked dataset, with initial size matching of the vector
    h5::ds_t ds = h5::write("example.h5", "path/chunked layout dataset", data,
    h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} | h5::gzip{9});
    //creates a contiguous layout dataset, with size matching `data`
    h5::ds_t ds = h5::write("example.h5", "path/contiguous layout dataset", data);
    //interop with HDF5 CAPI: will flush dataset `ds` by directly calling libhdf5 function
    H5Dflush(ds);