JUK1
test.cpp
Go to the documentation of this file.
1 #include <iostream>
3 #include <thread>
4 #include <complex>
5 #include <chrono>
6 
7 [[clang::optnone]] int
8 main() {
9  unsigned int nThreads = std::thread::hardware_concurrency();
10  std::cout << nThreads << " concurrent threads are supported.\n";
11 
12  std::cout << "2 x 2 Matrix\n" << std::endl;
13  Matrix<double> myMat(2, 2);
14  // std::cin >> d1 >> d2 >> d3 >> d4;
15  myMat(0, 0) = 1.0;
16  myMat(0, 1) = 1.0;
17  myMat(1, 0) = 1.0;
18  myMat(1, 1) = 2.0;
19  std::cout << " myMat\n" << myMat.toString();
20 
21  auto startTime = std::chrono::high_resolution_clock::now();
22  auto lu = myMat.luPair();
23  auto endTime = std::chrono::high_resolution_clock::now();
24  auto timeTaken = std::chrono::duration_cast<std::chrono::milliseconds>(endTime -
25  startTime)
26  .count();
27 
28  std::cout << timeTaken << "ms" << std::endl << lu.toString();
29 
30  std::cout << "4 x 4 Matrix\n" << std::endl;
31  Matrix<double> myMat4(4, 4);
32  Matrix<std::complex<double> > myCMat4(4, 4);
33  // std::cin >> d1 >> d2 >> d3 >> d4;
34  myMat4(0, 0) = 2.0;
35  myMat4(0, 1) = 1.0;
36  myMat4(0, 2) = 1.0;
37  myMat4(0, 3) = 0.0;
38  myMat4(1, 0) = 4.0;
39  myMat4(1, 1) = 3.0;
40  myMat4(1, 2) = 3.0;
41  myMat4(1, 3) = 1.0;
42  myMat4(2, 0) = 8.0;
43  myMat4(2, 1) = 7.0;
44  myMat4(2, 2) = 9.0;
45  myMat4(2, 3) = 5.0;
46  myMat4(3, 0) = 6.0;
47  myMat4(3, 1) = 7.0;
48  myMat4(3, 2) = 9.0;
49  myMat4(3, 3) = 8.0;
50 
51  Matrix<double> myCol(4, 1);
52  myCol(0, 0) = 1.0;
53  myCol(1, 0) = 0.0;
54  myCol(2, 0) = 3.0;
55  myCol(3, 0) = 0.0;
56 
57  myCMat4(0, 0) = 2.0;
58  myCMat4(0, 1) = 1.0;
59  myCMat4(0, 2) = 1.0;
60  myCMat4(0, 3) = 0.0;
61  myCMat4(1, 0) = 4.0;
62  myCMat4(1, 1) = 3.0;
63  myCMat4(1, 2) = 3.0;
64  myCMat4(1, 3) = 1.0;
65  myCMat4(2, 0) = 8.0;
66  myCMat4(2, 1) = 7.0;
67  myCMat4(2, 2) = 9.0;
68  myCMat4(2, 3) = 5.0;
69  myCMat4(3, 0) = 6.0;
70  myCMat4(3, 1) = 7.0;
71  myCMat4(3, 2) = 9.0;
72  myCMat4(3, 3) = 8.0;
73 
74  std::cout << " myMat\n" << myCMat4.toString();
75 
76  auto luC4 = myCMat4.luPair();
77  auto lu4 = myMat4.luPair();
78  std::cout << lu4.toString();
79  std::cout << luC4.toString();
80 
81  startTime = std::chrono::high_resolution_clock::now();
82  for (unsigned int i = 0; i < 1000000 /* ( unsigned int )-1*/; i++) {
83  lu4 = myMat4.luPair();
84  }
85  endTime = std::chrono::high_resolution_clock::now();
86  timeTaken = std::chrono::duration_cast<std::chrono::milliseconds>(endTime -
87  startTime)
88  .count();
89  std::cout << 1000000 << " 4 x 4 pairs in " << timeTaken << "ms" << std::endl;
90 
91  auto solved = myMat4.leftDivide(myCol);
92  std::cout << solved.toString();
93 
94  Matrix<double> myMat1000(1000, 1000);
95  for (size_t i = 0; i < 1000; i++) {
96  myMat1000(i, 1000 - 1 - i) = i + 10;
97  }
98  startTime = std::chrono::high_resolution_clock::now();
99  auto lu1000 = myMat1000.luPair();
100  endTime = std::chrono::high_resolution_clock::now();
101  timeTaken = std::chrono::duration_cast<std::chrono::milliseconds>(endTime -
102  startTime)
103  .count();
104  std::cout << "1000 x 1000 LU comp in " << timeTaken << "ms" << std::endl;
105 
106  // std::cout << lu1000.toString();
107 
108  return 0;
109 }
for i
A matrix class with support for LU-decomposition, and left division.
std::string toString() const
Matrix< T > leftDivide(const Matrix< T > &rhs) const
LUPair< T > luPair() const
int main()
Definition: test.cpp:8