11#include "../H5Easy.hpp"
17#include "../eigen.hpp"
24struct io_impl<T, typename std::enable_if<std::is_base_of<Eigen::DenseBase<T>, T>::value>::type> {
25 using EigenIndex = Eigen::DenseIndex;
29 inline static std::vector<size_t> file_shape(
const T& data) {
30 if (std::decay<T>::type::RowsAtCompileTime == 1) {
31 return {
static_cast<size_t>(data.cols())};
33 if (std::decay<T>::type::ColsAtCompileTime == 1) {
34 return {
static_cast<size_t>(data.rows())};
36 return inspector<T>::getDimensions(data);
40 inline static std::vector<size_t> mem_shape(
const T& data) {
41 return inspector<T>::getDimensions(data);
46 inline static std::vector<size_t> mem_shape(
const File& file,
47 const std::string& path,
49 std::vector<size_t> dims = dataset.getDimensions();
51 if (dims.size() == 1 && T::RowsAtCompileTime == 1) {
52 return std::vector<size_t>{1, dims[0]};
54 if (dims.size() == 1 && T::ColsAtCompileTime == 1) {
55 return std::vector<size_t>{dims[0], 1};
57 if (dims.size() == 2) {
61 throw detail::error(file, path,
"H5Easy::load: Inconsistent rank");
64 inline static DataSet
dump(File& file,
65 const std::string& path,
67 const DumpOptions& options) {
68 using value_type =
typename std::decay<T>::type::Scalar;
70 std::vector<size_t> file_dims = file_shape(data);
71 std::vector<size_t> mem_dims = mem_shape(data);
72 DataSet dataset = initDataset<value_type>(file, path, file_dims, options);
73 dataset.reshapeMemSpace(mem_dims).write(data);
74 if (options.flush()) {
80 inline static T
load(
const File& file,
const std::string& path) {
81 DataSet dataset = file.getDataSet(path);
82 std::vector<size_t> dims = mem_shape(file, path, dataset);
83 return dataset.reshapeMemSpace(dims).template read<T>();
87 const std::string& path,
88 const std::string& key,
90 const DumpOptions& options) {
91 using value_type =
typename std::decay<T>::type::Scalar;
93 std::vector<size_t> file_dims = file_shape(data);
94 std::vector<size_t> mem_dims = mem_shape(data);
95 Attribute attribute = initAttribute<value_type>(file, path, key, file_dims, options);
96 attribute.reshapeMemSpace(mem_dims).write(data);
97 if (options.flush()) {
104 const std::string& path,
105 const std::string& key) {
106 DataSet dataset = file.getDataSet(path);
107 Attribute attribute = dataset.getAttribute(key);
108 DataSpace dataspace = attribute.getSpace();
109 std::vector<size_t> dims = mem_shape(file, path, dataspace);
110 return attribute.reshapeMemSpace(dims).template read<T>();
Read/dump DataSets or Attribute using a minimalistic syntax. To this end, the functions are templated...
Definition H5Easy.hpp:62
DataSet dump(File &file, const std::string &path, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) DataSet in an open HDF5 file.
Definition H5Easy_public.hpp:99
T loadAttribute(const File &file, const std::string &path, const std::string &key)
Load a Attribute in an open HDF5 file to an object (templated).
Definition H5Easy_public.hpp:166
Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) Attribute in an open HDF5 file.
Definition H5Easy_public.hpp:148
T load(const File &file, const std::string &path, const std::vector< size_t > &idx)
Load entry {i, j, ...} from a DataSet in an open HDF5 file to a scalar.
Definition H5Easy_public.hpp:138