Skip to content

Commit

Permalink
Remove inspector::getSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Feb 19, 2024
1 parent 1a14333 commit fc74da7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/highfive/bits/H5Converter_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct DeepCopyBuffer {
using hdf5_type = typename inspector<type>::hdf5_type;

explicit DeepCopyBuffer(const std::vector<size_t>& _dims)
: buffer(inspector<T>::getSize(_dims))
: buffer(compute_total_size(_dims))
, dims(_dims) {}

hdf5_type* getPointer() {
Expand Down
29 changes: 4 additions & 25 deletions include/highfive/bits/H5Inspector_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ inspector<T> {
static constexpr size_t recursive_ndim
// Is the inner type trivially copyable for optimisation
// If this value is true: data() is mandatory
// If this value is false: getSize, serialize, unserialize are mandatory
// If this value is false: serialize, unserialize are mandatory
static constexpr bool is_trivially_copyable
// Reading:
// Allocate the value following dims (should be recursive)
static void prepare(type& val, const std::vector<std::size_t> dims)
// Return the size of the vector pass to/from hdf5 from a vector of dims
static size_t getSize(const std::vector<size_t>& dims)
// Return a pointer of the first value of val (for reading)
static hdf5_type* data(type& val)
// Take a serialized vector 'in', some dims and copy value to val (for reading)
Expand Down Expand Up @@ -169,10 +167,6 @@ struct type_helper {
return {};
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& /* val */, const std::vector<size_t>& /* dims */) {}

static hdf5_type* data(type& val) {
Expand Down Expand Up @@ -308,10 +302,6 @@ struct inspector<std::vector<T>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& val, const std::vector<size_t>& dims) {
val.resize(dims[0]);
std::vector<size_t> next_dims(dims.begin() + 1, dims.end());
Expand All @@ -332,7 +322,7 @@ struct inspector<std::vector<T>> {
static void serialize(const type& val, const std::vector<size_t>& dims, It m) {
if (!val.empty()) {
auto subdims = std::vector<size_t>(dims.begin() + 1, dims.end());
size_t subsize = inspector<value_type>::getSize(subdims);
size_t subsize = compute_total_size(subdims);
for (auto&& e: val) {
inspector<value_type>::serialize(e, subdims, m);
m += subsize;
Expand Down Expand Up @@ -366,13 +356,6 @@ struct inspector<std::vector<bool>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
if (dims.size() > 1) {
throw DataSpaceException("std::vector<bool> is only 1 dimension.");
}
return dims[0];
}

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims.size() > 1) {
throw DataSpaceException("std::vector<bool> is only 1 dimension.");
Expand Down Expand Up @@ -425,10 +408,6 @@ struct inspector<std::array<T, N>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims[0] > N) {
std::ostringstream os;
Expand All @@ -453,7 +432,7 @@ struct inspector<std::array<T, N>> {
template <class It>
static void serialize(const type& val, const std::vector<size_t>& dims, It m) {
auto subdims = std::vector<size_t>(dims.begin() + 1, dims.end());
size_t subsize = inspector<value_type>::getSize(subdims);
size_t subsize = compute_total_size(subdims);
for (auto& e: val) {
inspector<value_type>::serialize(e, subdims, m);
m += subsize;
Expand Down Expand Up @@ -555,7 +534,7 @@ struct inspector<T[N]> {
we will fix it one day */
static void serialize(const type& val, const std::vector<size_t>& dims, hdf5_type* m) {
auto subdims = std::vector<size_t>(dims.begin() + 1, dims.end());
size_t subsize = inspector<value_type>::getSize(subdims);
size_t subsize = compute_total_size(subdims);
for (size_t i = 0; i < N; ++i) {
inspector<value_type>::serialize(val[i], subdims, m + i * subsize);
}
Expand Down
12 changes: 2 additions & 10 deletions include/highfive/boost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ struct inspector<boost::multi_array<T, Dims>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims.size() < ndim) {
std::ostringstream os;
Expand Down Expand Up @@ -67,7 +63,7 @@ struct inspector<boost::multi_array<T, Dims>> {
static void serialize(const type& val, const std::vector<size_t>& dims, It m) {
size_t size = val.num_elements();
auto subdims = std::vector<size_t>(dims.begin() + ndim, dims.end());
size_t subsize = inspector<value_type>::getSize(subdims);
size_t subsize = compute_total_size(subdims);
for (size_t i = 0; i < size; ++i) {
inspector<value_type>::serialize(*(val.origin() + i), subdims, m + i * subsize);
}
Expand Down Expand Up @@ -104,10 +100,6 @@ struct inspector<boost::numeric::ublas::matrix<T>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims.size() < ndim) {
std::ostringstream os;
Expand All @@ -129,7 +121,7 @@ struct inspector<boost::numeric::ublas::matrix<T>> {
static void serialize(const type& val, const std::vector<size_t>& dims, hdf5_type* m) {
size_t size = val.size1() * val.size2();
auto subdims = std::vector<size_t>(dims.begin() + ndim, dims.end());
size_t subsize = inspector<value_type>::getSize(subdims);
size_t subsize = compute_total_size(subdims);
for (size_t i = 0; i < size; ++i) {
inspector<value_type>::serialize(*(&val(0, 0) + i), subdims, m + i * subsize);
}
Expand Down
4 changes: 0 additions & 4 deletions include/highfive/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ struct inspector<Eigen::Matrix<T, M, N>> {
return sizes;
}

static size_t getSize(const std::vector<size_t>& dims) {
return compute_total_size(dims);
}

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims[0] != static_cast<size_t>(val.rows()) ||
dims[1] != static_cast<size_t>(val.cols())) {
Expand Down

0 comments on commit fc74da7

Please sign in to comment.