9 #ifndef H5DATASPACE_MISC_HPP
10 #define H5DATASPACE_MISC_HPP
13 #include <initializer_list>
17 #include <H5Spublic.h>
27 :
DataSpace(std::vector<size_t>(items)) {}
29 template<
typename... Args>
31 :
DataSpace(std::vector<size_t>{dim1,
static_cast<size_t>(dims)...}) {}
33 template <
class IT,
typename>
35 std::vector<hsize_t> real_dims(begin, end);
37 if ((
_hid = H5Screate_simple(
int(real_dims.size()), real_dims.data(),
44 const std::vector<size_t>& maxdims) {
46 if (dims.size() != maxdims.size()) {
50 std::vector<hsize_t> real_dims(dims.begin(), dims.end());
51 std::vector<hsize_t> real_maxdims(maxdims.begin(), maxdims.end());
54 std::replace(real_maxdims.begin(), real_maxdims.end(),
57 if ((
_hid = H5Screate_simple(
int(dims.size()), real_dims.data(),
58 real_maxdims.data())) < 0) {
64 H5S_class_t h5_dataspace_type;
67 h5_dataspace_type = H5S_SCALAR;
70 h5_dataspace_type = H5S_NULL;
74 "datascape_scalar or datascape_null");
77 if ((
_hid = H5Screate(h5_dataspace_type)) < 0) {
84 if ((res.
_hid = H5Scopy(
_hid)) < 0) {
91 const int ndim = H5Sget_simple_extent_ndims(
_hid);
93 HDF5ErrMapper::ToException<DataSetException>(
94 "Unable to get dataspace number of dimensions");
102 if (H5Sget_simple_extent_dims(
_hid, dims.data(), NULL) < 0) {
103 HDF5ErrMapper::ToException<DataSetException>(
104 "Unable to get dataspace dimensions");
112 return std::accumulate(dims.begin(), dims.end(),
size_t{1u},
113 std::multiplies<size_t>());
118 if (H5Sget_simple_extent_dims(
_hid, NULL, maxdims.data()) < 0) {
119 HDF5ErrMapper::ToException<DataSetException>(
120 "Unable to get dataspace dimensions");
123 std::replace(maxdims.begin(), maxdims.end(), H5S_UNLIMITED,
128 template <
typename ScalarValue>
132 (std::is_arithmetic<ScalarValue>::value ||
133 std::is_enum<ScalarValue>::value ||
134 std::is_same<std::string, ScalarValue>::value),
135 "Only the following types are supported by DataSpace::From: \n"
136 " signed_arithmetic_types = int | long | float | double \n"
137 " unsigned_arithmetic_types = unsigned signed_arithmetic_types \n"
138 " string_types = std::string \n"
139 " all_basic_types = string_types | unsigned_arithmetic_types | "
140 "signed_arithmetic_types \n "
141 " stl_container_types = std::vector<all_basic_types> "
142 " boost_container_types = "
143 "boost::numeric::ublas::matrix<all_basic_types> | "
144 "boost::multi_array<all_basic_types> \n"
145 " all_supported_types = all_basic_types | stl_container_types | "
146 "boost_container_types"
147 " eigen_matrix_type = Eigen::Matrix<signed_arithmetic_type> | Eigen::VectorXX");
151 template <
typename Value>
153 return DataSpace(details::get_dim_vector<Value>(container));
156 template <
typename ValueT, std::
size_t N>
161 template <std::
size_t N, std::
size_t W
idth>
167 template <
typename Value, std::
size_t N>
173 template <
typename Value, std::
size_t Dims>
176 std::vector<size_t> dims(container.shape(), container.shape() + Dims);
180 template <
typename Value>
183 std::vector<size_t> dims(2);
184 dims[0] = mat.size1();
185 dims[1] = mat.size2();
191 template <
typename Value,
int M,
int N>
194 std::vector<size_t> dims{
static_cast<size_t>(mat.rows()),
195 static_cast<size_t>(mat.cols())};
199 template <
typename Value,
int M,
int N>
202 using elem_t = Eigen::Matrix<Value, M, N>;
203 std::vector<size_t> dims{
204 std::accumulate(vec.begin(), vec.end(),
size_t{0u},
205 [](
size_t so_far,
const elem_t& v) {
206 return so_far + static_cast<size_t>(v.rows());
208 static_cast<size_t>(vec[0].cols())};
213 template <
typename Value,
int M,
int N,
size_t Dims>
215 From(
const boost::multi_array<Eigen::Matrix<Value, M, N>, Dims>& vec) {
216 std::vector<size_t> dims(vec.shape(), vec.shape() + Dims);
217 dims[Dims - 1] *=
static_cast<size_t>(vec.origin()->rows() * vec.origin()->cols());
229 if (input_dims == dataset_dims)
233 for (
auto i = dims.crbegin(); i != --dims.crend() && *i == 1; ++i)
236 if (input_dims == dataset_dims)
239 dataset_dims = dims.size();
240 for (
auto i = dims.cbegin(); i != --dims.cend() && *i == 1; ++i)
243 if (input_dims == dataset_dims)
247 return input_dims == 0 && dataset_dims == 1 && dims[dims.size() - 1] == 1;
253 #endif // H5DATASPACE_MISC_HPP