6#include <boost/numeric/ublas/matrix.hpp>
12struct inspector<boost::numeric::ublas::matrix<T>> {
13 using type = boost::numeric::ublas::matrix<T>;
14 using value_type = unqualified_t<T>;
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 = 2;
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_copyable;
24 static constexpr bool is_trivially_nestable =
false;
26 static size_t getRank(
const type& val) {
27 return ndim + inspector<value_type>::getRank(val(0, 0));
30 static std::vector<size_t> getDimensions(
const type& val) {
31 std::vector<size_t> sizes{val.size1(), val.size2()};
32 auto s = inspector<value_type>::getDimensions(val(0, 0));
33 sizes.insert(sizes.end(), s.begin(), s.end());
37 static void prepare(type& val,
const std::vector<size_t>& dims) {
38 if (dims.size() < ndim) {
39 std::ostringstream os;
40 os <<
"Impossible to pair DataSet with " << dims.size() <<
" dimensions into a " << ndim
41 <<
" boost::numeric::ublas::matrix";
42 throw DataSpaceException(os.str());
44 val.resize(dims[0], dims[1],
false);
47 static hdf5_type* data(type& val) {
48 return inspector<value_type>::data(val(0, 0));
51 static const hdf5_type* data(
const type& val) {
52 return inspector<value_type>::data(val(0, 0));
55 static void serialize(
const type& val,
const std::vector<size_t>& dims, hdf5_type* m) {
56 size_t size = val.size1() * val.size2();
57 auto subdims = std::vector<size_t>(dims.begin() + ndim, dims.end());
59 for (
size_t i = 0; i < size; ++i) {
60 inspector<value_type>::serialize(*(&val(0, 0) + i), subdims, m + i * subsize);
64 static void unserialize(
const hdf5_type* vec_align,
65 const std::vector<size_t>& dims,
67 std::vector<size_t> next_dims(dims.begin() + ndim, dims.end());
69 size_t size = val.size1() * val.size2();
70 for (
size_t i = 0; i < size; ++i) {
71 inspector<value_type>::unserialize(vec_align + i * subsize,
Definition assert_compatible_spaces.hpp:15
size_t compute_total_size(const std::vector< size_t > &dims)
Definition compute_total_size.hpp:10