QMCPACK
hyperslab_proxy< CT, RANK > Struct Template Reference

class to use file space hyperslab with a serialized container More...

+ Collaboration diagram for hyperslab_proxy< CT, RANK >:

Public Types

using element_type = typename container_traits< CT >::element_type
 
using SpaceType = h5_space_type< element_type, RANK >
 type alias for h5_space_type encapsulates both RANK and ranks contributed by element_type for constructing an hdf5 dataspace. More...
 

Public Member Functions

template<typename IT >
 hyperslab_proxy (CT &a, const std::array< IT, RANK > &dims_in, const std::array< IT, RANK > &selected_in, const std::array< IT, RANK > &offsets_in)
 constructor More...
 
hsize_t size (int i) const
 return the size of the i-th dimension of global space More...
 
void checkUserRankSizes () const
 checks if file_space, elected_space and offset are self-consistent More...
 
bool checkContainerCapacity () const
 check if the container is large enough for the selected space and resize if requested More...
 
template<typename IT >
void adaptShape (const std::vector< IT > &sizes_file)
 adjust file_space and selected_space shapes based on sizes_file More...
 

Public Attributes

SpaceType file_space
 global dimension of the hyperslab More...
 
SpaceType selected_space
 local dimension of the hyperslab More...
 
std::array< hsize_t, SpaceType::rankslab_offset
 offset of the hyperslab More...
 
CT & ref_
 container reference More...
 

Static Public Attributes

static const unsigned int slab_rank = RANK
 user rank of a hyperslab More...
 

Detailed Description

template<typename CT, unsigned RANK>
struct qmcplusplus::hyperslab_proxy< CT, RANK >

class to use file space hyperslab with a serialized container

Template Parameters
CTcontainer type, std::vector, Vector, Matrix, Array, boost::multi::array
RANKhyperslab user rank. The dimensions contributed by T are excluded.

The container may get resized for sufficient space if the template specialization of container_traits<CT> is available additional restriction: 1D containers can be resized to hold any multi-dimensional data >1D containers can only be resize to hold data with matching dimensions.

Definition at line 35 of file hdf_hyperslab.h.

Member Typedef Documentation

◆ element_type

Definition at line 40 of file hdf_hyperslab.h.

◆ SpaceType

type alias for h5_space_type encapsulates both RANK and ranks contributed by element_type for constructing an hdf5 dataspace.

Definition at line 45 of file hdf_hyperslab.h.

Constructor & Destructor Documentation

◆ hyperslab_proxy()

hyperslab_proxy ( CT &  a,
const std::array< IT, RANK > &  dims_in,
const std::array< IT, RANK > &  selected_in,
const std::array< IT, RANK > &  offsets_in 
)
inline

constructor

Template Parameters
ITinteger type
Parameters
adata containter
dims_indimension sizes of a dataset.
selected_indimension sizes of the selected part of the dataset
offsets_inoffsets of the selected part of the dataset

value 0 in any dimension of dims_in or selected_in is allowed when reading a dataset. The actual size is derived from file dataset.

element_type related dimensions always have offset 0

Definition at line 66 of file hdf_hyperslab.h.

References h5_space_type< T, RANK >::dims, hyperslab_proxy< CT, RANK >::file_space, h5_space_type< element_type, RANK >::rank, hyperslab_proxy< CT, RANK >::selected_space, hyperslab_proxy< CT, RANK >::slab_offset, and hyperslab_proxy< CT, RANK >::slab_rank.

70  : ref_(a)
71  {
72  static_assert(std::is_unsigned<IT>::value, "only accept unsigned integer types like size_t");
73  for (int i = 0; i < slab_rank; ++i)
74  {
75  file_space.dims[i] = static_cast<hsize_t>(dims_in[i]);
76  selected_space.dims[i] = static_cast<hsize_t>(selected_in[i]);
77  slab_offset[i] = static_cast<hsize_t>(offsets_in[i]);
78  }
79 
80  /// element_type related dimensions always have offset 0
81  for (int i = slab_rank; i < SpaceType::rank; ++i)
82  slab_offset[i] = 0;
83  }
std::array< hsize_t, SpaceType::rank > slab_offset
offset of the hyperslab
Definition: hdf_hyperslab.h:51
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
CT & ref_
container reference
Definition: hdf_hyperslab.h:53
SpaceType selected_space
local dimension of the hyperslab
Definition: hdf_hyperslab.h:49
SpaceType file_space
global dimension of the hyperslab
Definition: hdf_hyperslab.h:47
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49
static const unsigned int slab_rank
user rank of a hyperslab
Definition: hdf_hyperslab.h:38

Member Function Documentation

◆ adaptShape()

void adaptShape ( const std::vector< IT > &  sizes_file)
inline

adjust file_space and selected_space shapes based on sizes_file

Template Parameters
ITinteger type
Parameters
sizes_filesizes of all the user dimensions of a dataset

This function can only be used when reading a dataset not writing if the size value of a dimension is 0, use the value based on the dataset on disk

Definition at line 130 of file hdf_hyperslab.h.

References h5_space_type< T, RANK >::dims, hyperslab_proxy< CT, RANK >::file_space, hyperslab_proxy< CT, RANK >::selected_space, and hyperslab_proxy< CT, RANK >::slab_rank.

Referenced by h5data_proxy< hyperslab_proxy< CT, RANK > >::read().

131  {
132  // validate user ranks
133  if (sizes_file.size() != slab_rank)
134  throw std::runtime_error("User specified and filespace dimensions mismatch!\n");
135 
136  for (int dim = 0; dim < slab_rank; dim++)
137  {
138  if (file_space.dims[dim] == 0)
139  file_space.dims[dim] = sizes_file[dim];
140  else if (file_space.dims[dim] != sizes_file[dim])
141  {
142  std::ostringstream err_msg;
143  err_msg << "dim " << dim << " user specified size " << file_space.dims[dim] << " filespace size "
144  << sizes_file[dim] << " mismatched!" << std::endl;
145  throw std::runtime_error(err_msg.str());
146  }
147 
148  if (selected_space.dims[dim] == 0)
149  selected_space.dims[dim] = file_space.dims[dim];
150  }
151  }
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
SpaceType selected_space
local dimension of the hyperslab
Definition: hdf_hyperslab.h:49
SpaceType file_space
global dimension of the hyperslab
Definition: hdf_hyperslab.h:47
static const unsigned int slab_rank
user rank of a hyperslab
Definition: hdf_hyperslab.h:38

◆ checkContainerCapacity()

bool checkContainerCapacity ( ) const
inline

check if the container is large enough for the selected space and resize if requested

Definition at line 114 of file hdf_hyperslab.h.

References h5_space_type< T, RANK >::dims, hyperslab_proxy< CT, RANK >::ref_, hyperslab_proxy< CT, RANK >::selected_space, and hyperslab_proxy< CT, RANK >::slab_rank.

Referenced by h5data_proxy< hyperslab_proxy< CT, RANK > >::read(), and h5data_proxy< hyperslab_proxy< CT, RANK > >::write().

115  {
116  hsize_t total_size = slab_rank > 0 ? 1 : 0;
117  for (int dim = 0; dim < slab_rank; dim++)
118  total_size *= selected_space.dims[dim];
119  return total_size > container_traits<CT>::getSize(ref_) ? false : true;
120  }
static size_t getSize(const CT &ref)
get the current linear storage size of a container
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
CT & ref_
container reference
Definition: hdf_hyperslab.h:53
SpaceType selected_space
local dimension of the hyperslab
Definition: hdf_hyperslab.h:49
static const unsigned int slab_rank
user rank of a hyperslab
Definition: hdf_hyperslab.h:38

◆ checkUserRankSizes()

void checkUserRankSizes ( ) const
inline

checks if file_space, elected_space and offset are self-consistent

Definition at line 92 of file hdf_hyperslab.h.

References h5_space_type< T, RANK >::dims, hyperslab_proxy< CT, RANK >::file_space, hyperslab_proxy< CT, RANK >::selected_space, hyperslab_proxy< CT, RANK >::slab_offset, and hyperslab_proxy< CT, RANK >::slab_rank.

Referenced by h5data_proxy< hyperslab_proxy< CT, RANK > >::read(), and h5data_proxy< hyperslab_proxy< CT, RANK > >::write().

93  {
94  if (std::any_of(file_space.dims, file_space.dims + slab_rank, [](int i) { return i == 0; }))
95  throw std::runtime_error("Zero size detected in some dimensions of filespace\n");
96  if (std::any_of(selected_space.dims, selected_space.dims + slab_rank, [](int i) { return i == 0; }))
97  throw std::runtime_error("Zero size detected in some dimensions of selected filespace\n");
98  for (int dim = 0; dim < slab_rank; dim++)
99  {
100  if (slab_offset[dim] > file_space.dims[dim])
101  throw std::runtime_error("offset outsdie the bound of filespace");
102  if (slab_offset[dim] + selected_space.dims[dim] > file_space.dims[dim])
103  {
104  std::ostringstream err_msg;
105  err_msg << "dim " << dim << " offset " << slab_offset[dim] << " + selected_space size "
106  << selected_space.dims[dim] << " outsdie the bound of filespace " << file_space.dims[dim] << std::endl;
107  throw std::runtime_error(err_msg.str());
108  }
109  }
110  }
std::array< hsize_t, SpaceType::rank > slab_offset
offset of the hyperslab
Definition: hdf_hyperslab.h:51
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
SpaceType selected_space
local dimension of the hyperslab
Definition: hdf_hyperslab.h:49
SpaceType file_space
global dimension of the hyperslab
Definition: hdf_hyperslab.h:47
static const unsigned int slab_rank
user rank of a hyperslab
Definition: hdf_hyperslab.h:38

◆ size()

hsize_t size ( int  i) const
inline

return the size of the i-th dimension of global space

Parameters
idimension

Definition at line 88 of file hdf_hyperslab.h.

References h5_space_type< T, RANK >::dims, hyperslab_proxy< CT, RANK >::file_space, and h5_space_type< element_type, RANK >::rank.

88 { return (i > SpaceType::rank) ? 0 : file_space.dims[i]; }
hsize_t dims[RANK > 0 ? RANK :1]
shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0 ...
Definition: hdf_dataspace.h:47
SpaceType file_space
global dimension of the hyperslab
Definition: hdf_hyperslab.h:47
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49

Member Data Documentation

◆ file_space

◆ ref_

◆ selected_space

◆ slab_offset

◆ slab_rank


The documentation for this struct was generated from the following file: