#include <armadillo>
#include <h5cpp/all>
#include <iostream>
int main() {
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
{
arma::vec v = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
bool ok = (back.n_elem == v.n_elem) && arma::approx_equal(v, back, "absdiff", 0.0);
check("arma::vec(8) shape + values", ok);
}
{
arma::mat M = arma::linspace<arma::mat>(1, 12, 12).reshape(3, 4);
bool shape = (back.n_rows == M.n_rows) && (back.n_cols == M.n_cols);
bool values = shape && arma::approx_equal(M, back, "absdiff", 1e-12);
check("arma::mat(3x4) shape + values", shape && values);
}
{
arma::cube C(2, 3, 4);
for (arma::uword s = 0; s < C.n_slices; ++s)
for (arma::uword r = 0; r < C.n_rows; ++r)
for (arma::uword c = 0; c < C.n_cols; ++c)
C(r, c, s) = double(s * 100 + r * 10 + c);
bool shape = (back.n_rows == C.n_rows)
&& (back.n_cols == C.n_cols)
&& (back.n_slices == C.n_slices);
bool values = shape && arma::approx_equal(C, back, "absdiff", 0.0);
check("arma::cube(2x3x4) 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