QMCPACK
test_TinyVector.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) 2017 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
8 //
9 // File created by: Mark Dewing, markdewing@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "catch.hpp"
14 
15 #include "OhmmsPETE/TinyVector.h"
16 
17 #include <stdio.h>
18 #include <string>
19 #include <iostream>
20 
21 using std::string;
22 
23 
24 bool pass = true;
25 namespace qmcplusplus
26 {
27 template<unsigned int D>
29 {
31 
32  vec_t v1;
33  // default constructor sets elements to zero
34  for (int i = 0; i < D; i++)
35  {
36  CHECK(v1[i] == Approx(0.0));
37  }
38 
39  vec_t v2(1.0);
40  // single constructor sets all the elements to that value
41  for (int i = 0; i < D; i++)
42  {
43  CHECK(v2[i] == Approx(1.0));
44  }
45 
46  // TODO: add optional bounds checks to element access methods
47  vec_t v4;
48  double sum = 0;
49  for (int i = 0; i < D; i++)
50  {
51  sum += 1.0 * i;
52  v4[i] = 1.0 * i;
53  }
54 
55  // Dot product
56  double dotp = dot(v2, v4);
57  CHECK(sum == Approx(dotp));
58 
59  // Multiply add
60  v1 += 2.0 * v4;
61  REQUIRE(2.0 * sum == dot(v2, v1));
62 }
63 
64 template<unsigned int D>
66 {
68  vec_t v3(1.0, 2.0);
69  CHECK(v3[0] == Approx(1.0));
70  CHECK(v3[1] == Approx(2.0));
71  // problem: elements past those explicitly set are undefined
72  // in this case, vectors with D > 2 will have undefined elements.
73 }
74 
75 TEST_CASE("tiny vector", "[OhmmsPETE]")
76 {
77  test_tiny_vector<1>();
78  test_tiny_vector<2>();
79  test_tiny_vector<3>();
80  test_tiny_vector<4>();
81  test_tiny_vector_size_two<2>();
82  test_tiny_vector_size_two<3>();
83  test_tiny_vector_size_two<4>();
84 }
85 
86 TEST_CASE("tiny vector operator out", "[OhmmsPETE]")
87 {
88  TinyVector<double, 3> point{0.0, -0.0, 1.0};
89  std::ostringstream ostr;
90  ostr << point;
91  std::string expected{" 0 0 1"};
92  CHECK(expected == ostr.str());
93 }
94 
95 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
REQUIRE(std::filesystem::exists(filename))
bool pass
void test_tiny_vector_size_two()
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void test_tiny_vector()