#include <iostream>
#include <blitz/array.h>
#include <h5cpp/all>
template <class T> using Vec1D = blitz::Array<T, 1>;
template <class T> using Mat2D = blitz::Array<T, 2>;
template <class T> using Cube3D = blitz::Array<T, 3>;
int main() {
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
{
Vec1D<double> v(8);
for (int i = 0; i < v.size(); ++i) v(i) = i + 1.0;
bool shape = (back.extent(0) == v.extent(0));
bool values = shape;
for (int i = 0; values && i < v.size(); ++i) values = values && (back(i) == v(i));
check("blitz::Array<double,1>(8) shape + values", shape && values);
}
{
Mat2D<short> M(3, 4);
for (int r = 0; r < M.rows(); ++r)
for (int c = 0; c < M.cols(); ++c)
M(r, c) = static_cast<short>(r * M.cols() + c);
bool shape = (back.rows() == M.rows()) && (back.cols() == M.cols());
bool values = shape;
for (int r = 0; values && r < M.rows(); ++r)
for (int c = 0; values && c < M.cols(); ++c)
values = values && (back(r, c) == M(r, c));
check("blitz::Array<short,2>(3x4) shape + values", shape && values);
}
{
Cube3D<float> C(2, 3, 4);
for (int i = 0; i < C.extent(0); ++i)
for (int j = 0; j < C.extent(1); ++j)
for (int k = 0; k < C.extent(2); ++k)
C(i, j, k) = float(i * 100 + j * 10 + k);
bool shape = (back.extent(0) == C.extent(0))
&& (back.extent(1) == C.extent(1))
&& (back.extent(2) == C.extent(2));
bool values = shape;
for (int i = 0; values && i < C.extent(0); ++i)
for (int j = 0; values && j < C.extent(1); ++j)
for (int k = 0; values && k < C.extent(2); ++k)
values = values && (back(i, j, k) == C(i, j, k));
check("blitz::Array<float,3>(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