6#include <boost/multi_array.hpp>
11template <
typename T,
size_t Dims>
12struct inspector<boost::multi_array<T, Dims>> {
13 using type = boost::multi_array<T, Dims>;
15 using base_type =
typename inspector<value_type>::base_type;
16 using hdf5_type =
typename inspector<value_type>::hdf5_type;
18 static constexpr size_t ndim = Dims;
19 static constexpr size_t min_ndim = ndim + inspector<value_type>::min_ndim;
20 static constexpr size_t max_ndim = ndim + inspector<value_type>::max_ndim;
22 static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
23 inspector<value_type>::is_trivially_nestable;
24 static constexpr bool is_trivially_nestable =
false;
27 static size_t getRank(
const type& val) {
28 return ndim + inspector<value_type>::getRank(val.data()[0]);
31 static std::vector<size_t> getDimensions(
const type& val) {
32 auto rank = getRank(val);
33 std::vector<size_t> sizes(rank, 1ul);
34 for (
size_t i = 0; i < ndim; ++i) {
35 sizes[i] = val.shape()[i];
37 if (val.size() != 0) {
38 auto s = inspector<value_type>::getDimensions(val.data()[0]);
39 sizes.resize(ndim + s.size());
40 for (
size_t i = 0; i < s.size(); ++i) {
41 sizes[ndim + i] = s[i];
47 static void prepare(type& val,
const std::vector<size_t>& dims) {
48 if (dims.size() < ndim) {
49 std::ostringstream os;
50 os <<
"Only '" << dims.size() <<
"' given but boost::multi_array is of size '" << ndim
52 throw DataSpaceException(os.str());
54 boost::array<typename type::index, Dims> ext;
55 std::copy(dims.begin(), dims.begin() + ndim, ext.begin());
57 std::vector<size_t> next_dims(dims.begin() + Dims, dims.end());
58 std::size_t size = std::accumulate(dims.begin(),
61 std::multiplies<size_t>());
62 for (
size_t i = 0; i < size; ++i) {
63 inspector<value_type>::prepare(*(val.origin() + i), next_dims);
67 static void assert_c_order(
const type& val) {
68 if (!(val.storage_order() == boost::c_storage_order())) {
69 throw DataTypeException(
"Only C storage order is supported for 'boost::multi_array'.");
73 static hdf5_type* data(type& val) {
75 return inspector<value_type>::data(*val.data());
78 static const hdf5_type* data(
const type& val) {
80 return inspector<value_type>::data(*val.data());
84 static void serialize(
const type& val,
const std::vector<size_t>& dims, It m) {
86 size_t size = val.num_elements();
87 auto subdims = std::vector<size_t>(dims.begin() + ndim, dims.end());
89 for (
size_t i = 0; i < size; ++i) {
90 inspector<value_type>::serialize(*(val.origin() + i), subdims, m + i * subsize);
95 static void unserialize(It vec_align,
const std::vector<size_t>& dims, type& val) {
97 std::vector<size_t> next_dims(dims.begin() + ndim, dims.end());
99 for (
size_t i = 0; i < val.num_elements(); ++i) {
100 inspector<value_type>::unserialize(vec_align + i * subsize,
102 *(val.origin() + i));
Definition assert_compatible_spaces.hpp:15
size_t compute_total_size(const std::vector< size_t > &dims)
Definition compute_total_size.hpp:10