An open API service indexing awesome lists of open source software.

https://github.com/garrison/eigen3-hdf5

Bare-bones hdf5 serialization of Eigen matrices and vectors
https://github.com/garrison/eigen3-hdf5

eigen3 hdf5

Last synced: 10 months ago
JSON representation

Bare-bones hdf5 serialization of Eigen matrices and vectors

Awesome Lists containing this project

README

          

eigen3-hdf5
===========

.. image:: https://github.com/garrison/eigen3-hdf5/actions/workflows/main.yml/badge.svg
:target: https://github.com/garrison/eigen3-hdf5/actions

Easy serialization of C++ `Eigen `_
matrices using `HDF5 `_.

The library is meant to be bare-bones (at least for now). It gets me
90% of what I want/need in a few hundred lines of code. It may also
get you 90% (or even 100%) of what you need.

Requirements
------------

* Eigen3 (tested on 3.1 and 3.2 branches)
* HDF5 C++ wrapper library >= 1.8.12 (yes, this is a very recent
version)

Because ``eigen3-hdf5`` is a template library, there is nothing to link
against (besides the HDF5 libraries).

API
---

Supports saving and restoring Eigen matrices and vectors of ``float``,
``double``, ``long double``, ``int``, ``unsigned int``, and
``std::complex<>``.

.. code:: c++

#include

void save_matrix()
{
Eigen::Matrix3d mat;
mat << 1, 2, 3, 4, 5, 6, 7, 8, 9;
H5::H5File file("filename1.h5", H5F_ACC_TRUNC);
EigenHDF5::save(file, "MatrixDataSetName", mat);
}

void load_vector()
{
Eigen::Vector4i vec;
H5::H5File file("filename2.h5", H5F_ACC_RDONLY);
EigenHDF5::load(file, "VectorDataSetName", vec);
}

See the `unittests `_ directory for more examples.

Unit tests
----------

I am using `premake4 `_ and
`googletest `_ because I am
familiar with them.

The unit tests currently write to specific files in the current
directory. This could change, eventually.

The GitHub Action can be approximated locally by installing `act
`_ and running::

act -P ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04

License
-------

MIT license.

Next steps
----------

* Support more fundamental data types

Thoughts/notes
--------------

* Using the HDF5 C++ wrapper library supposedly means it `won't work
with parallel hdf5
`_. If I were to
do it again, I would write ``eigen3-hdf5`` using the regular C HDF5
API, not the C++ wrapper. Patches are welcome. :)