QMCPACK
ConvertToReal.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) 2021 QMCPACK developers.
6 //
7 // File developed by: Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory
11 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
12 //
13 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #ifndef QMCPLUSPLUS_CONVERT2REAL_H
18 #define QMCPLUSPLUS_CONVERT2REAL_H
19 
20 #include <complex>
21 #include "complex_help.hpp"
22 #include "OhmmsPETE/OhmmsMatrix.h"
23 #include "OhmmsPETE/Tensor.h"
24 #include "OhmmsPETE/OhmmsVector.h"
25 #include "OhmmsPETE/TinyVector.h"
26 
27 namespace qmcplusplus
28 {
29 /** generic conversion from type T1 to type T2 using implicit conversion
30 */
31 template<typename T1, typename T2, IsReal<T2> = true>
32 inline void convertToReal(const T1& in, T2& out)
33 {
34  out = static_cast<T2>(in);
35 }
36 
37 /** specialization of conversion from complex to real
38 */
39 template<typename T1, typename T2, IsReal<T2> = true>
40 inline void convertToReal(const std::complex<T1>& in, T2& out)
41 {
42  out = in.real();
43 }
44 
45 /* specialization of D-dim vectors
46  *
47  */
48 template<typename T1, typename T2, unsigned D>
50 {
51  for (int i = 0; i < D; ++i)
52  convertToReal(in[i], out[i]);
53 }
54 
55 /** specialization for D tensory*/
56 template<typename T1, typename T2, unsigned D>
57 inline void convertToReal(const Tensor<T1, D>& in, Tensor<T2, D>& out)
58 {
59  for (int i = 0; i < D * D; ++i)
60  convertToReal(in[i], out[i]);
61 }
62 
63 /** generic function to convert arrays
64  * @param in starting address of type T1
65  * @param out starting address of type T2
66  * @param n size of in/out
67  */
68 template<typename T1, typename T2>
69 inline void convertToReal(const T1* restrict in, T2* restrict out, std::size_t n)
70 {
71  for (int i = 0; i < n; ++i)
72  convertToReal(in[i], out[i]);
73 }
74 
75 /** specialization for a vector */
76 template<typename T1, typename T2>
77 inline void convertToReal(const Vector<T1>& in, Vector<T2>& out)
78 {
79  convertToReal(in.data(), out.data(), in.size());
80 }
81 
82 /** specialization for a vector */
83 template<typename T1, typename T2>
84 inline void convertToReal(const Matrix<T1>& in, Matrix<T2>& out)
85 {
86  convertToReal(in.data(), out.data(), in.size());
87 }
88 
89 } // namespace qmcplusplus
90 #endif
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void convertToReal(const T1 &in, T2 &out)
generic conversion from type T1 to type T2 using implicit conversion
Definition: ConvertToReal.h:32
size_type size() const
Definition: OhmmsMatrix.h:76
size_type size() const
return the current size
Definition: OhmmsVector.h:162
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
Declaraton of Vector<T,Alloc> Manage memory through Alloc directly and allow referencing an existing ...