13template <
typename T,
int M,
int N>
14struct inspector<Eigen::Matrix<T, M, N>> {
15 using type = Eigen::Matrix<T, M, N>;
17 using base_type =
typename inspector<value_type>::base_type;
18 using hdf5_type = base_type;
20 static constexpr size_t ndim = 2;
21 static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
22 static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
23 inspector<value_type>::is_trivially_copyable;
26 static void assert_not_buggy(Eigen::Index nrows, Eigen::Index ncols) {
27 if (nrows > 1 && ncols > 1) {
28 throw std::runtime_error(
29 "HighFive has been broken for Eigen::Matrix. Please check "
30 "https://github.com/BlueBrain/HighFive/issues/532.");
34 static std::vector<size_t> getDimensions(
const type& val) {
35 assert_not_buggy(val.rows(), val.cols());
37 std::vector<size_t> sizes{
static_cast<size_t>(val.rows()),
static_cast<size_t>(val.cols())};
38 auto s = inspector<value_type>::getDimensions(val.data()[0]);
39 sizes.insert(sizes.end(), s.begin(), s.end());
43 static size_t getSizeVal(
const type& val) {
47 static size_t getSize(
const std::vector<size_t>& dims) {
51 static void prepare(type& val,
const std::vector<size_t>& dims) {
52 if (dims[0] !=
static_cast<size_t>(val.rows()) ||
53 dims[1] !=
static_cast<size_t>(val.cols())) {
54 val.resize(
static_cast<typename type::Index
>(dims[0]),
55 static_cast<typename type::Index
>(dims[1]));
58 assert_not_buggy(val.rows(), val.cols());
61 static hdf5_type* data(type& val) {
62 assert_not_buggy(val.rows(), val.cols());
63 return inspector<value_type>::data(*val.data());
66 static const hdf5_type* data(
const type& val) {
67 assert_not_buggy(val.rows(), val.cols());
68 return inspector<value_type>::data(*val.data());
71 static void serialize(
const type& val, hdf5_type* m) {
72 assert_not_buggy(val.rows(), val.cols());
73 std::memcpy(m, val.data(),
static_cast<size_t>(val.size()) *
sizeof(hdf5_type));
76 static void unserialize(
const hdf5_type* vec_align,
77 const std::vector<size_t>& dims,
79 assert_not_buggy(val.rows(), val.cols());
80 if (dims.size() < 2) {
81 std::ostringstream os;
82 os <<
"Impossible to pair DataSet with " << dims.size()
83 <<
" dimensions into an eigen-matrix.";
84 throw DataSpaceException(os.str());
size_t getSize(const File &file, const std::string &path)
Get the size of an existing DataSet in an open HDF5 file.
Definition H5Easy_public.hpp:82
Definition H5_definitions.hpp:22
size_t compute_total_size(const std::vector< size_t > &dims)
Definition H5Inspector_decl.hpp:10