QMCPACK
container_traits_ohmms.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) 2019 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Lab
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Lab
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_CONTAINER_TRAITS_OHMMS_H
14 #define QMCPLUSPLUS_CONTAINER_TRAITS_OHMMS_H
15 
16 #include <sstream>
18 #include "OhmmsPETE/OhmmsVector.h"
19 #include "OhmmsPETE/OhmmsMatrix.h"
20 #include "OhmmsPETE/OhmmsArray.h"
21 
22 namespace qmcplusplus
23 {
24 // template specialization for Ohmms Vector/Matrix/Array
25 template<typename T, class ALLOC>
26 struct container_traits<Vector<T, ALLOC>>
27 {
28  using element_type = T;
30 
31  template<typename I>
32  inline static void resize(CT& ref, I* n, int d)
33  {
34  size_t nt = d > 0 ? 1 : 0;
35  for (int i = 0; i < d; ++i)
36  nt *= n[i];
37  ref.resize(nt);
38  }
39 
40  inline static size_t getSize(const CT& ref) { return ref.size(); }
41 
42  inline static auto getElementPtr(CT& ref) { return ref.data(); }
43 };
44 
45 template<typename T, class ALLOC>
46 struct container_traits<Matrix<T, ALLOC>>
47 {
48  using element_type = T;
50 
51  template<typename I>
52  inline static void resize(CT& ref, I* n, int d)
53  {
54  if (d != 2)
55  {
56  std::ostringstream err_msg;
57  err_msg << "Matrix cannot be resized. Requested dimension = " << d << std::endl;
58  throw std::runtime_error(err_msg.str());
59  }
60  ref.resize(n[0], n[1]);
61  }
62 
63  inline static size_t getSize(const CT& ref) { return ref.size(); }
64 
65  inline static auto getElementPtr(CT& ref) { return ref.data(); }
66 };
67 
68 template<typename T, unsigned D>
69 struct container_traits<Array<T, D>>
70 {
71  using element_type = T;
72  using CT = Array<T, D>;
73 
74  template<typename I>
75  inline static void resize(CT& ref, I* n, int d)
76  {
77  if (d != D)
78  {
79  std::ostringstream err_msg;
80  err_msg << "Array<T, " << D << "> cannot be resized. Requested dimension = " << d << std::endl;
81  throw std::runtime_error(err_msg.str());
82  }
83  ref.resize(n);
84  }
85 
86  inline static size_t getSize(const CT& ref) { return ref.size(); }
87 
88  inline static auto getElementPtr(CT& ref) { return ref.data(); }
89 };
90 
91 } // namespace qmcplusplus
92 #endif
void resize(size_type n, Type_t val=Type_t())
Resize the container.
Definition: OhmmsVector.h:166
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Type_t * data()
Definition: OhmmsArray.h:87
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
size_type size() const
Definition: OhmmsMatrix.h:76
size_type size() const
return the current size
Definition: OhmmsVector.h:162
size_t size() const
Definition: OhmmsArray.h:57
std::complex< double > I
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...
A D-dimensional Array class based on PETE.
Definition: OhmmsArray.h:25