QMCPACK
test_vector_soa.cpp
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: Peter Doak, doakpw@ornl.gov, Oak Ridge National Lab
8 // Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "catch.hpp"
15 
17 
18 #include <stdio.h>
19 #include <string>
20 
21 using std::string;
22 
23 namespace qmcplusplus
24 {
25 TEST_CASE("vector", "[OhmmsSoA]")
26 {
28  using vec_soa_t = VectorSoaContainer<double, 3>;
29 
30  vec_t R(4);
31  vec_soa_t RSoA(4);
32 
33  R[0] = TinyVector<double, 3>(0.00000000, 0.00000000, 0.00000000);
34  R[1] = TinyVector<double, 3>(1.68658058, 1.68658058, 1.68658058);
35  R[2] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
36  R[3] = TinyVector<double, 3>(5.05974172, 5.05974172, 1.68658058);
37 
38  RSoA.copyIn(R);
39 
40  //check in value
41  CHECK(R[1][0] == Approx(1.68658058));
42  CHECK(R[1][1] == Approx(1.68658058));
43  CHECK(R[1][2] == Approx(1.68658058));
44 
45  //check out value
46  CHECK(RSoA[1][0] == Approx(1.68658058));
47  CHECK(RSoA[1][1] == Approx(1.68658058));
48  CHECK(RSoA[1][2] == Approx(1.68658058));
49 
50  //check view value
51  vec_soa_t RSoA_view(RSoA.data(), RSoA.size(), RSoA.capacity());
52  CHECK(RSoA_view[1][0] == Approx(1.68658058));
53  CHECK(RSoA_view[1][1] == Approx(1.68658058));
54  CHECK(RSoA_view[1][2] == Approx(1.68658058));
55 }
56 
57 TEST_CASE("VectorSoaContainer copy constructor", "[OhmmsSoA]")
58 {
61 
62  R[0] = TinyVector<double, 3>(0.00000000, 0.00000000, 0.00000000);
63  R[1] = TinyVector<double, 3>(1.68658058, 1.68658058, 1.68658058);
64  R[2] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
65  R[3] = TinyVector<double, 3>(5.05974172, 5.05974172, 1.68658058);
66 
67  RSoA.copyIn(R);
68 
69  VectorSoaContainer<double, 3> rsoa_copy(RSoA);
70 
71  // more importantly this test shall not leak memory
72 
73  //check out value
74  CHECK(rsoa_copy[1][0] == Approx(1.68658058));
75  CHECK(rsoa_copy[1][1] == Approx(1.68658058));
76  CHECK(rsoa_copy[1][2] == Approx(1.68658058));
77 }
78 
79 TEST_CASE("VectorSoaContainer move constructor", "[OhmmsSoA]")
80 {
83 
84  R[0] = TinyVector<double, 3>(0.00000000, 0.00000000, 0.00000000);
85  R[1] = TinyVector<double, 3>(1.68658058, 1.68658058, 1.68658058);
86  R[2] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
87  R[3] = TinyVector<double, 3>(5.05974172, 5.05974172, 1.68658058);
88 
89  RSoA.copyIn(R);
90 
91  VectorSoaContainer<double, 3> rsoa_move(std::move(RSoA));
92 
93  // more importantly this test shall not leak memory
94 
95  //check out value
96  CHECK(rsoa_move[1][0] == Approx(1.68658058));
97  CHECK(rsoa_move[1][1] == Approx(1.68658058));
98  CHECK(rsoa_move[1][2] == Approx(1.68658058));
99 }
100 
101 TEST_CASE("VectorSoaContainer assignment", "[OhmmsSoA]")
102 {
105 
106  R[0] = TinyVector<double, 3>(0.00000000, 0.00000000, 0.00000000);
107  R[1] = TinyVector<double, 3>(1.68658058, 1.68658058, 1.68658058);
108  R[2] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
109  R[3] = TinyVector<double, 3>(5.05974172, 5.05974172, 1.68658058);
110  RSoA.copyIn(R);
111 
112  VectorSoaContainer<double, 3> rsoa_assign;
113  rsoa_assign = RSoA;
114  CHECK(rsoa_assign[3][0] == Approx(5.05974172));
115  CHECK(rsoa_assign[3][1] == Approx(5.05974172));
116  CHECK(rsoa_assign[3][2] == Approx(1.68658058));
117 
119  VectorSoaContainer<double, 3> r_soa_big(5);
120 
121  r_big[0] = TinyVector<double, 3>(0.00000000, 0.00000000, 0.00000000);
122  r_big[1] = TinyVector<double, 3>(1.68658058, 1.68658058, 1.68658058);
123  r_big[2] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
124  r_big[3] = TinyVector<double, 3>(5.05974172, 5.05974172, 1.68658058);
125  r_big[4] = TinyVector<double, 3>(3.37316115, 3.37316115, 0.00000000);
126 
127  r_soa_big.copyIn(r_big);
128 
129  rsoa_assign = r_soa_big;
130  CHECK(rsoa_assign[4][0] == Approx(3.37316115));
131  CHECK(rsoa_assign[4][2] == Approx(0.00000000));
132 }
133 
134 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Soa Container for D-dim vectors.
SoA adaptor class for Vector<TinyVector<T,D> >
void copyIn(const Vector< TinyVector< T, D >> &in)
AoS to SoA : copy from Vector<TinyVector<>>
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))