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,
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()) {
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());
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()) {
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());
87 #endif // H5_USE_XTENSOR
88 #endif // H5EASY_BITS_XTENSOR_HPP