Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inspector::is_trivially_nestable. #986

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 17 additions & 5 deletions include/highfive/bits/H5Inspector_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ inspector<T> {
// If this value is false: serialize, unserialize are mandatory
static constexpr bool is_trivially_copyable

// Is this type trivially nestable, i.e. is type[n] a contiguous
// array of `base_type[N]`?
static constexpr bool is_trivially_nestable

// Reading:
// Allocate the value following dims (should be recursive)
static void prepare(type& val, const std::vector<std::size_t> dims)
Expand Down Expand Up @@ -162,6 +166,7 @@ struct type_helper {
static constexpr size_t ndim = 0;
static constexpr size_t recursive_ndim = ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<type>::value;
static constexpr bool is_trivially_nestable = is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& /* val */) {
return {};
Expand Down Expand Up @@ -206,6 +211,7 @@ struct inspector<bool>: type_helper<bool> {
using hdf5_type = int8_t;

static constexpr bool is_trivially_copyable = false;
static constexpr bool is_trivially_nestable = false;

static hdf5_type* data(type& /* val */) {
throw DataSpaceException("A boolean cannot be read directly.");
Expand Down Expand Up @@ -255,6 +261,7 @@ struct inspector<Reference>: type_helper<Reference> {
using hdf5_type = hobj_ref_t;

static constexpr bool is_trivially_copyable = false;
static constexpr bool is_trivially_nestable = false;

static hdf5_type* data(type& /* val */) {
throw DataSpaceException("A Reference cannot be read directly.");
Expand Down Expand Up @@ -287,7 +294,8 @@ struct inspector<std::vector<T>> {
static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = false;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes(recursive_ndim, 1ul);
Expand Down Expand Up @@ -350,6 +358,7 @@ struct inspector<std::vector<bool>> {
static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim;
static constexpr bool is_trivially_copyable = false;
static constexpr bool is_trivially_nestable = false;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{val.size()};
Expand Down Expand Up @@ -396,8 +405,9 @@ struct inspector<std::array<T, N>> {
static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
sizeof(type) == N * sizeof(T) &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = (sizeof(type) == N * sizeof(T)) &&
is_trivially_copyable;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{N};
Expand Down Expand Up @@ -466,7 +476,8 @@ struct inspector<T*> {
static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = false;

static std::vector<size_t> getDimensions(const type& /* val */) {
throw DataSpaceException("Not possible to have size of a T*");
Expand Down Expand Up @@ -496,7 +507,8 @@ struct inspector<T[N]> {
static constexpr size_t ndim = 1;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = is_trivially_copyable;

static void prepare(type& val, const std::vector<size_t>& dims) {
if (dims.size() < 1) {
Expand Down
5 changes: 4 additions & 1 deletion include/highfive/boost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ struct inspector<boost::multi_array<T, Dims>> {
static constexpr size_t ndim = Dims;
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = false;


static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes;
Expand Down Expand Up @@ -92,6 +94,7 @@ struct inspector<boost::numeric::ublas::matrix<T>> {
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
static constexpr bool is_trivially_nestable = false;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{val.size1(), val.size2()};
Expand Down
3 changes: 2 additions & 1 deletion include/highfive/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ struct eigen_inspector {
static constexpr size_t recursive_ndim = ndim + inspector<value_type>::recursive_ndim;
static constexpr bool is_trivially_copyable = is_row_major() &&
std::is_trivially_copyable<value_type>::value &&
inspector<value_type>::is_trivially_copyable;
inspector<value_type>::is_trivially_nestable;
static constexpr bool is_trivially_nestable = false;

static std::vector<size_t> getDimensions(const type& val) {
std::vector<size_t> sizes{static_cast<size_t>(val.rows()), static_cast<size_t>(val.cols())};
Expand Down