Skip to content

Commit 2ead5cc

Browse files
committed
Merge branch 'refactor/matrix'
2 parents cf61204 + a87915e commit 2ead5cc

File tree

3 files changed

+21
-44
lines changed

3 files changed

+21
-44
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
### Changed
88

9+
#### Internals
10+
11+
- Refactor `Matrix` template class (#1089)
12+
913
#### CI
1014

1115
- Update GitHub Actions (#1094)

src/structures/generic/matrix.cpp

-38
This file was deleted.

src/structures/generic/matrix.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All rights reserved (see LICENSE).
1010
1111
*/
1212

13-
#include <initializer_list>
13+
#include <vector>
1414

1515
#include "structures/typedefs.h"
1616

@@ -22,13 +22,24 @@ template <class T> class Matrix {
2222
std::vector<T> data;
2323

2424
public:
25-
Matrix();
25+
Matrix() : Matrix(0) {
26+
}
2627

27-
explicit Matrix(std::size_t n);
28+
explicit Matrix(std::size_t n) : Matrix(n, 0) {
29+
}
2830

29-
Matrix(std::size_t n, T value);
31+
Matrix(std::size_t n, T value) : n(n), data(n * n, value) {
32+
}
3033

31-
Matrix<T> get_sub_matrix(const std::vector<Index>& indices) const;
34+
Matrix<T> get_sub_matrix(const std::vector<Index>& indices) const {
35+
Matrix<T> sub_matrix(indices.size());
36+
for (std::size_t i = 0; i < indices.size(); ++i) {
37+
for (std::size_t j = 0; j < indices.size(); ++j) {
38+
sub_matrix[i][j] = (*this)[indices[i]][indices[j]];
39+
}
40+
}
41+
return sub_matrix;
42+
}
3243

3344
T* operator[](std::size_t i) {
3445
return data.data() + (i * n);
@@ -44,7 +55,7 @@ template <class T> class Matrix {
4455
#if USE_PYTHON_BINDINGS
4556
T* get_data() {
4657
return data.data();
47-
};
58+
}
4859
#endif
4960
};
5061

0 commit comments

Comments
 (0)