#include <iostream>
#include <Eigen/Dense>
#include <h5cpp/all>
template <class T> using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
template <class T> using Array = Eigen::Array <T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>;
int main() {
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
{
Matrix<double> M = Matrix<double>::Random(3, 4);
bool shape = (back.rows() == M.rows()) && (back.cols() == M.cols());
bool values = shape && M.isApprox(back, 0.0);
check("Eigen::Matrix<double>(3x4) shape + values", shape && values);
}
{
Array<float> A(2, 5);
for (Eigen::Index r = 0; r < A.rows(); ++r)
for (Eigen::Index c = 0; c < A.cols(); ++c)
A(r, c) = float(r * A.cols() + c);
bool shape = (back.rows() == A.rows()) && (back.cols() == A.cols());
bool values = shape && ((A == back).all());
check("Eigen::Array<float>(2x5) shape + values", shape && values);
}
{
Matrix<double> v(8, 1);
for (Eigen::Index i = 0; i < v.rows(); ++i) v(i, 0) = i + 1.0;
bool shape = (back.rows() == v.rows()) && (back.cols() == v.cols());
bool values = shape && v.isApprox(back, 0.0);
check("Eigen column-vec(8x1) shape + values", shape && values);
}
return 0;
}
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
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
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