QMCPACK
test_Matrix.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) 2016 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 #include <cstdio>
15 #include <string>
16 
17 #include "OhmmsPETE/OhmmsMatrix.h"
18 #include "config.h"
19 
20 using std::string;
21 
22 namespace qmcplusplus
23 {
24 TEST_CASE("matrix", "[OhmmsPETE]")
25 {
26  using Mat = Matrix<OHMMS_PRECISION>;
27  Mat A(3, 3);
28  Mat B(3, 3);
29  Mat C(3, 3);
30 
31  for (int i = 0; i < 3; i++)
32  {
33  for (int j = 0; j < 3; j++)
34  {
35  B(i, j) = (i + j) * 2.1;
36  }
37  }
38 
39  // Assign to all elements
40  A = 1.0;
41 
42  // Assignment. This eventually generates a call to 'evaluate' in OhmmsVector.h
43  C = A;
44 
45  // *= operator in OhmmMatrixOperators.h
46  A *= 3.1;
47 
48  // iterator
49  Mat::iterator ia = A.begin();
50  for (; ia != A.end(); ia++)
51  {
52  CHECK(*ia == Approx(3.1));
53  }
54 
55  REQUIRE( A == A);
56  REQUIRE( A != C);
57 
58  // copy constructor and copy method
59  Mat D(C);
60  CHECK(D.rows() == 3);
61  CHECK(D.cols() == 3);
62 
63  // swap_rows
64  A(0, 0) = 0.0;
65  A(0, 1) = 1.0;
66  A(1, 0) = 1.0;
67  A(1, 1) = 2.0;
68  A.swap_rows(0, 1);
69  CHECK(A(0, 0) == 1.0);
70  CHECK(A(0, 1) == 2.0);
71  CHECK(A(1, 0) == 0.0);
72  CHECK(A(1, 1) == 1.0);
73  // swap_cols
74  A.swap_cols(0, 1);
75  CHECK(A(0, 0) == 2.0);
76  CHECK(A(0, 1) == 1.0);
77  CHECK(A(1, 0) == 1.0);
78  CHECK(A(1, 1) == 0.0);
79 }
80 
81 TEST_CASE("matrix converting assignment", "[OhmmsPETE]")
82 {
83  Matrix<double> mat_A(3,3);
84  Matrix<float> mat_B(3,3);
85 
86  for (int i = 0; i < 3; i++)
87  for (int j = 0; j < 3; j++)
88  mat_A(i, j) = (i + j) * 2.1;
89 
90  mat_B = mat_A;
91 
92  CHECK(mat_B(0,0) == Approx(0));
93  CHECK(mat_B(1,1) == Approx(4.2));
94 
95  Matrix<float> mat_C(2,2);
96  for (int i = 0; i < 2; i++)
97  for (int j = 0; j < 2; j++)
98  mat_C(i, j) = (i + j) * 2.2;
99 
100  mat_A.assignUpperLeft(mat_C);
101  CHECK(mat_A(1,0) == Approx(2.2));
102  CHECK(mat_A(1,2) == Approx(6.3));
103 
104  Matrix<float> mat_D(4,4);
105  for (int i = 0; i < 4; i++)
106  for (int j = 0; j < 4; j++)
107  mat_D(i, j) = (i + j) * 2.3;
108 
109  mat_A.assignUpperLeft(mat_D);
110  CHECK(mat_A(1,0) == Approx(2.3));
111  CHECK(mat_A(1,2) == Approx(6.9));
112 }
113 
114 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
void assignUpperLeft(const Matrix< T_FROM, ALLOC_FROM > &from)
This assigns from a matrix with larger row size (used for alignment) to whatever the rowsize is here...
Definition: OhmmsMatrix.h:155
REQUIRE(std::filesystem::exists(filename))
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
double B(double x, int k, int i, const std::vector< double > &t)