9#ifndef H5EASY_BITS_XTENSOR_HPP
10#define H5EASY_BITS_XTENSOR_HPP
12#include "../H5Easy.hpp"
13#include "H5Easy_misc.hpp"
14#include "H5Easy_scalar.hpp"
16#ifdef H5GT_USE_XTENSOR
23struct is_xtensor : std::false_type {};
25struct is_xtensor<xt::xarray<T>> : std::true_type {};
26template <
class T,
size_t N>
27struct is_xtensor<xt::xtensor<T, N>> : std::true_type {};
30struct 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());
57 inline static Attribute dumpAttribute(File& file,
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()) {
71 inline static T loadAttribute(
const File& file,
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());