Welcome to the documentation!¶
Installation¶
This library serves as an interface wrapper for using the HDF5 library with Eigen objects. As a result, all Eigen Matrix types are able to be written to HDF5 objects and subsequently read back. In addition, all HDF5 structures, such as files, groups, and datasets are compatible with Eigen data types.
Dependencies¶
This library depends on the following:
Build Scripts¶
Several bash
scripts are available which simplify the dependency installtion process.
Usage of these scripts is not required if the dependencies are already installed or managed seperately.
Build and Installation¶
Basic Usage¶
This file is a convinient header to include all of the HDF5 Eigen functionality into your program. You can utilize it by adding the following to your source code and ensuring that the library is available to your compiler
#include "hdf5.hpp"
Here is a simple program which shows how to write and read an Eigen matrix from an HDF5 data file.
#include "hdf5.hpp"
#include <Eigen/Dense>
#include <iostream>
void write_data() {
Eigen::MatrixXd matrix(3, 3);
matrix << 1, 2, 3, 4, 5, 6, 7, 8, 9;
// open the file
HDF5::File hf = HDF5::File("filename.hdf5", HDF5::File::Truncate);
// write the data
hf.write("dataset_name", matrix);
std::cout << "Original Matrix: " << std::endl;
std::cout << matrix << std::endl;
}
void read_data() {
// open the file for reading
HDF5::File hf = HDF5::File("filename.hdf5", HDF5::File::ReadOnly);
Eigen::MatrixXd matrix;
hf.read("dataset_name", matrix);
std::cout << "Matrix read: " << std::endl;
std::cout << matrix << std::endl;
}
int main() {
write_data();
read_data();
return 0;
}
The write_data()
function is used to write an Eigen::MatrixXd
object to an HDF5::File hf
instance.
Likewise, the read_data()
function then opens the same file, in a read-only mode, and print the matrix to the screen.
Basic HDF5 Tutorial¶
Describe HDF5 File, Groups, Dataset ideas
Compare to file structure
Talk about attributes for data
Give some background on why it’s better than other storage methods
HDF5 File¶
This module provides functionality for dealing with HDF5::File
objects.
-
class
File
¶ Public Functions
-
File
(void)¶
-
virtual
~File
(void)¶
-
const std::string
getName
(void) const¶
-
template<typename
Derived
>
DataSetdataset
(const std::string &name, const Eigen::EigenBase<Derived> &mat) const¶
-
template<typename
Derived
>
DataSetread_dataset
(const std::string &dataset_name, const Eigen::DenseBase<Derived> &mat) const¶
-
template<typename
Derived
>
DataSetwrite_dataset
(const std::string &dataset_name, const Eigen::EigenBase<Derived> &mat) const¶
Public Members
-
std::shared_ptr<H5::H5File>
file_ptr
¶ HDF5 file to save data
-
HDF5 Group¶
This module provides functionality for dealing with HDF5::Group
objects.
-
class
Group
¶ Public Functions
-
Group
(void)¶
-
virtual
~Group
(void)¶
-
template<typename
Derived
>
DataSetdataset
(const std::string &name, const Eigen::EigenBase<Derived> &mat) const¶
Public Members
-
std::shared_ptr<H5::Group>
group_ptr
¶
-
HDF5 Dataset¶
This module provides functionality for dealing with HDF5::DataSet
objects.
HDF5 Eigen Wrapper¶
Many of the core HDF5 functionality is contained here. The more complicated details required to read and write Eigen objects happens here and should typically not be utilized directly
Functions
-
template<typename
Derived
>
voidload
(const H5::H5Location &h5group, const std::string &name, const Eigen::DenseBase<Derived> &mat)¶ This will read from an HDF5 file/group and save the data into an eigen matrix. One should have some idea about the eigen array before reading
- Author
Shankar Kulumani
- Version
26 April 2018
- Parameters
h5group
: H5 group or file to read fromname
: String name of the datasetmat
: Eigen variable to save data
-
template<typename
Derived
>
voidsave
(H5::H5Location &h5group, const std::string &name, const Eigen::EigenBase<Derived> &mat, const H5::DSetCreatPropList &plist = H5::DSetCreatPropList::DEFAULT)¶ This will write Eigen data to an HDF5 file or group
- Author
Shankar Kulumani
- Version
26 April 2018
- Parameters
h5group
: The H5 group or file to write toname
: string name of the datasetmat
: Eigen variable to save dataplist
: The dataset property list
-
template<typename
T
>
classDatatypeSpecialization
¶ - #include <hdf5_eigen.hpp>
Convert a C++ datatype to the equivalent in HDF5 land.
All Eigen functionality to read/write to HDF5
Updated/corrected from the work of Jim Garrison https://github.com/garrison/eigen3-hdf5
Each dataset must define the correct type in the
HDF5. This template class handles that by automatially determining the HDF5 type from a Eigen input.- Author
Shankar Kulumani
- Version
26 April 2018
Setup primiarly for Eigen types but needs to be extended.
- Author
Shankar Kulumani
- Version
26 April 2018
-
template<>
structDatatypeSpecialization
<float>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)¶
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<double>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<long double>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<short>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<unsigned short>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<int>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<unsigned int>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<long>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<unsigned long>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<long long>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<unsigned long long>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<const char *>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<>
structDatatypeSpecialization
<char *>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<std::size_t
N
>
structDatatypeSpecialization
<const char[N]>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
template<std::size_t
N
>
structDatatypeSpecialization
<char[N]>¶ - #include <hdf5_eigen.hpp>
Public Static Functions
-
static const H5::DataType *
get
(void)
-
static const H5::DataType *
-
namespace
internal
¶ Functions
-
template<typename
Derived
>
H5::DataSpacecreate_dataspace
(const Eigen::EigenBase<Derived> &mat)¶ Create the dataspace required for the HDF5 dataset
- Return
H5::DataSpace Defines the space required to store mat
- Author
Shankar Kulumani
- Version
26 April 2018
- Parameters
mat
: Eigen matrix to write to the file
-
template<typename
Derived
>
boolwrite_rowmat
(const Eigen::EigenBase<Derived> &mat, const H5::DataType *const datatype, H5::DataSet *dataset, const H5::DataSpace *dspace)¶
-
template<typename
Derived
>
boolwrite_colmat
(const Eigen::EigenBase<Derived> &mat, const H5::DataType *const datatype, H5::DataSet *dataset, const H5::DataSpace *dspace)¶
-
template<typename
Scalar
>
voidread_data
(const H5::DataSet &dataset, Scalar *data, const H5::DataType &datatype)¶
-
template<typename
Scalar
>
voidread_data
(const H5::Attribute &dataset, Scalar *data, const H5::DataType &datatype)¶
-
template<typename
Derived
>
boolread_colmat
(const Eigen::DenseBase<Derived> &mat, const H5::DataType *const datatype, const H5::Attribute &dataset)¶
-
template<typename