QMCPACK
test_ConstantSizeMatrix.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) 2020 QMCPACK developers.
6 //
7 // File developed by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
8 //
9 // File created by: Peter Doak, doakpw@ornl.gov, Oak Ridge National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
13 #include "OhmmsPETE/OhmmsMatrix.h"
14 
15 #include "catch.hpp"
16 
17 
18 namespace qmcplusplus
19 {
20 TEST_CASE("ConstantSizeMatrix basics", "[containers]")
21 {
22  ConstantSizeMatrix<double> cmat(1, 9, 1, 32, 0.0);
23  CHECK(cmat.size() == 9);
24  CHECK(cmat.capacity() == 32);
25 
26  CHECK_NOTHROW(cmat.resize(1, 16));
27  CHECK(cmat.size() == 16);
28  CHECK(cmat.capacity() == 32);
29 
30  CHECK_THROWS(cmat.resize(1, 33));
31  CHECK_THROWS(cmat.resize(34, 2));
32 
33  CHECK_NOTHROW(cmat.resize(2, 9));
34  CHECK(cmat.capacity() == 32);
35 
36  CHECK_NOTHROW(cmat.resize(3, 9));
37  CHECK(cmat.capacity() == 32);
38 
39  //note the odd OhmmsMatrix style access operator semantics
40  //If these break you probably breaking other weird QMCPACK code.
41  std::vector<double> svec(16, 1.0);
42  cmat = svec;
43  double& matrices_d = cmat(0);
44  CHECK(matrices_d == Approx(1.0));
45  matrices_d = 4.0;
46  CHECK(cmat(0) == Approx(4.0));
47  CHECK(*(cmat[0]) == Approx(4.0));
48 
49  ConstantSizeMatrix<double> cmat2(2, 8, 2, 16, 0.0);
50  std::vector<double> svec2(16, 2.0);
51  svec.insert(svec.end(), svec2.begin(), svec2.end());
52  cmat2 = svec;
53  CHECK(*(cmat2[0]) == Approx(1.0));
54  CHECK(*(cmat2[0] + 1) == Approx(1.0));
55  CHECK(*(cmat2[1]) == Approx(2.0));
56 
57  ConstantSizeMatrix<double> cmat3(4, 32, 4, 32, 0.0);
58  CHECK_NOTHROW(cmat3.resize(2, 64));
59  CHECK(cmat3.size() == 128);
60  CHECK(cmat3.capacity() == 128);
61 
62  CHECK_NOTHROW(cmat3.resize(8, 16));
63  CHECK(cmat3.size() == 128);
64  CHECK(cmat3.capacity() == 128);
65 }
66 
67 TEST_CASE("ConstantSizeMatrix Ohmms integration", "[containers]")
68 {
69  ConstantSizeMatrix<double> cmat(2, 8, 2, 32, 0.0);
70  Matrix<double> omat(2, 9);
71  omat = 2.0;
72  cmat = omat;
73 
74  CHECK(cmat.size() == 18);
75  CHECK(*omat[1] == 2.0);
76 }
77 
78 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
Drop in replacement for OhmmsMatrix as a storage object backed by PooledMemory, does not support PETE...
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))