9 #ifndef H5EASY_BITS_XTENSOR_HPP
10 #define H5EASY_BITS_XTENSOR_HPP
12 #include "../H5Easy.hpp"
23 struct io_impl<T, typename std::enable_if<xt::is_xexpression<T>::value>::type> {
25 inline static std::vector<size_t> shape(
const T& data) {
26 return std::vector<size_t>(data.shape().cbegin(), data.shape().cend());
29 inline static DataSet
dump(File& file,
30 const std::string& path,
32 const DumpOptions& options) {
33 using value_type =
typename std::decay_t<T>::value_type;
34 DataSet dataset = initDataset<value_type>(file, path, shape(data), options);
35 dataset.write_raw(data.data());
36 if (options.flush()) {
42 inline static T
load(
const File& file,
const std::string& path) {
43 static_assert(xt::has_data_interface<T>::value,
44 "Cannot load to xt::xfunction or xt::xgenerator, use e.g. xt::xtensor or xt::xarray");
45 DataSet dataset = file.getDataSet(path);
46 std::vector<size_t> dims = dataset.getDimensions();
47 T data = T::from_shape(dims);
48 dataset.read(data.data());
53 const std::string& path,
54 const std::string& key,
56 const DumpOptions& options) {
57 using value_type =
typename std::decay_t<T>::value_type;
58 Attribute attribute = initAttribute<value_type>(file, path, key, shape(data), options);
59 attribute.write_raw(data.data());
60 if (options.flush()) {
67 const std::string& path,
68 const std::string& key) {
69 static_assert(xt::has_data_interface<T>::value,
70 "Cannot load to xt::xfunction or xt::xgenerator, use e.g. xt::xtensor or xt::xarray");
71 DataSet dataset = file.getDataSet(path);
72 Attribute attribute = dataset.getAttribute(key);
73 DataSpace dataspace = attribute.getSpace();
74 std::vector<size_t> dims = dataspace.getDimensions();
75 T data = T::from_shape(dims);
76 attribute.read(data.data());
Read/dump DataSets or Attribute using a minimalistic syntax. To this end, the functions are templated...
Definition: H5Easy.hpp:60
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:115
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:185
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:167
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:157