QMCPACK
hdf_dataspace.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef QMCPLUSPLUS_HDF_DATASPACE_TRAITS_H
15 #define QMCPLUSPLUS_HDF_DATASPACE_TRAITS_H
16 
17 /**@file hdf_dataspace.h
18  * @brief define h5_space_type to handle basic datatype for hdf5
19  *
20  * h5_space_type is a helper class for h5data_proxy and used internally
21  * - h5_space_type<T,RANK>
22  * - h5_space_type<std::complex<T>,RANK>
23  * - h5_space_type<std::array<T,D>,RANK>
24  * - h5_space_type<TinyVector<T,D>,RANK>
25  * - h5_space_type<TinyVector<std::complex<T>,D>,RANK> // removed, picked up by template recursion
26  * - h5_space_type<Tensor<T,D>,RANK>
27  * - h5_space_type<Tensor<std::complex<T>,D>,RANK> // removed, picked up by template recursion
28  */
29 
30 #include <complex>
31 #include <array>
32 #include "hdf_datatype.h"
33 #include "OhmmsPETE/TinyVector.h"
34 #include "OhmmsPETE/Tensor.h"
35 
36 namespace qmcplusplus
37 {
38 /** default struct to define a h5 dataspace, any intrinsic type T
39  *
40  * @tparam T intrinsic datatype
41  * @tparam RANK rank of the multidimensional h5dataspace
42  */
43 template<typename T, hsize_t RANK>
45 {
46  ///shape of the dataspace, protected for zero size array, hdf5 support scalar as rank = 0
47  hsize_t dims[RANK > 0 ? RANK : 1];
48  ///rank of the multidimensional dataspace
49  static constexpr hsize_t rank = RANK;
50  ///new rank added due to T
51  static constexpr int added_rank() { return 0; }
52  ///return the address
53  inline static auto get_address(T* a) { return a; }
54  inline static auto get_address(const T* a) { return a; }
55 };
56 
57 /** specialization of h5_space_type for std::complex<T>
58  *
59  * Raize the dimension of the space by 1 and set the last dimension=2
60  */
61 template<typename T, hsize_t RANK>
62 struct h5_space_type<std::complex<T>, RANK> : public h5_space_type<T, RANK + 1>
63 {
65  using Base::dims;
66  using Base::rank;
67  static constexpr int added_rank() { return Base::added_rank() + 1; }
68  inline h5_space_type() { dims[RANK] = 2; }
69  inline static auto get_address(std::complex<T>* a) { return Base::get_address(reinterpret_cast<T*>(a)); }
70  inline static auto get_address(const std::complex<T>* a) { return Base::get_address(reinterpret_cast<const T*>(a)); }
71 };
72 
73 /** specialization of h5_space_type for std::array<T,D> for any intrinsic type T
74  */
75 template<typename T, std::size_t D, hsize_t RANK>
76 struct h5_space_type<std::array<T, D>, RANK> : public h5_space_type<T, RANK + 1>
77 {
79  using Base::dims;
80  using Base::rank;
81  inline h5_space_type() { dims[RANK] = D; }
82  static constexpr int added_rank() { return Base::added_rank() + 1; }
83  inline static auto get_address(std::array<T, D>* a) { return Base::get_address(a->data()); }
84  inline static auto get_address(const std::array<T, D>* a) { return Base::get_address(a->data()); }
85 };
86 
87 /** specialization of h5_space_type for TinyVector<T,D> for any intrinsic type T
88  */
89 template<typename T, unsigned D, hsize_t RANK>
90 struct h5_space_type<TinyVector<T, D>, RANK> : public h5_space_type<T, RANK + 1>
91 {
93  using Base::dims;
94  using Base::rank;
95  inline h5_space_type() { dims[RANK] = D; }
96  static constexpr int added_rank() { return Base::added_rank() + 1; }
97  inline static auto get_address(TinyVector<T, D>* a) { return Base::get_address(a->data()); }
98  inline static auto get_address(const TinyVector<T, D>* a) { return Base::get_address(a->data()); }
99 };
100 
101 /** specialization of h5_space_type for Tensor<T,D> for any intrinsic type T
102  */
103 template<typename T, unsigned D, hsize_t RANK>
104 struct h5_space_type<Tensor<T, D>, RANK> : public h5_space_type<T, RANK + 2>
105 {
107  using Base::dims;
108  using Base::rank;
109  inline h5_space_type()
110  {
111  dims[RANK] = D;
112  dims[RANK + 1] = D;
113  }
114  static constexpr int added_rank() { return Base::added_rank() + 2; }
115  inline static auto get_address(Tensor<T, D>* a) { return Base::get_address(a->data()); }
116  inline static auto get_address(const Tensor<T, D>* a) { return Base::get_address(a->data()); }
117 };
118 
119 } // namespace qmcplusplus
120 #endif
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
default struct to define a h5 dataspace, any intrinsic type T
Definition: hdf_dataspace.h:44
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
static auto get_address(const TinyVector< T, D > *a)
Definition: hdf_dataspace.h:98
static auto get_address(const T *a)
Definition: hdf_dataspace.h:54
static auto get_address(const std::array< T, D > *a)
Definition: hdf_dataspace.h:84
static auto get_address(TinyVector< T, D > *a)
Definition: hdf_dataspace.h:97
static auto get_address(const std::complex< T > *a)
Definition: hdf_dataspace.h:70
static auto get_address(std::complex< T > *a)
Definition: hdf_dataspace.h:69
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
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
static auto get_address(std::array< T, D > *a)
Definition: hdf_dataspace.h:83
static auto get_address(T *a)
return the address
Definition: hdf_dataspace.h:53
static constexpr hsize_t rank
rank of the multidimensional dataspace
Definition: hdf_dataspace.h:49
static constexpr int added_rank()
new rank added due to T
Definition: hdf_dataspace.h:51
Type_t * data()
Definition: Tensor.h:267
std::vector< int > dims
static auto get_address(const Tensor< T, D > *a)