9 #ifndef H5EASY_BITS_XTENSOR_HPP
10 #define H5EASY_BITS_XTENSOR_HPP
12 #include "../H5Easy.hpp"
23 struct is_xtensor : std::false_type {};
25 struct is_xtensor<xt::xarray<T>> : std::true_type {};
26 template <
class T,
size_t N>
27 struct is_xtensor<xt::xtensor<T, N>> : std::true_type {};
30 struct io_impl<T, typename std::enable_if<is_xtensor<T>::value>::type> {
32 inline static std::vector<size_t> shape(
const T& data) {
33 return std::vector<size_t>(data.shape().cbegin(), data.shape().cend());
36 inline static DataSet
dump(File& file,
37 const std::string& path,
39 const DumpOptions& options) {
40 using value_type =
typename std::decay_t<T>::value_type;
41 DataSet dataset = initDataset<value_type>(file, path, shape(data), options);
42 dataset.write_raw(data.data());
43 if (options.flush()) {
49 inline static T
load(
const File& file,
const std::string& path) {
50 DataSet dataset = file.getDataSet(path);
51 std::vector<size_t> dims = dataset.getDimensions();
52 T data = T::from_shape(dims);
53 dataset.read(data.data());
58 const std::string& path,
59 const std::string& key,
61 const DumpOptions& options) {
62 using value_type =
typename std::decay_t<T>::value_type;
63 Attribute attribute = initAttribute<value_type>(file, path, key, shape(data), options);
64 attribute.write_raw(data.data());
65 if (options.flush()) {
72 const std::string& path,
73 const std::string& key) {
74 DataSet dataset = file.getDataSet(path);
75 Attribute attribute = dataset.getAttribute(key);
76 DataSpace dataspace = attribute.getSpace();
77 std::vector<size_t> dims = dataspace.getDimensions();
78 T data = T::from_shape(dims);
79 attribute.read(data.data());
Definition: H5Easy.hpp:51
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 rank-two DataSet in an open HDF5 file to a scalar.
Definition: H5Easy_public.hpp:157