Skip to content

Commit

Permalink
Merge branch 'refactor/matrix'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Apr 29, 2024
2 parents cf61204 + a87915e commit 2ead5cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Changed

#### Internals

- Refactor `Matrix` template class (#1089)

#### CI

- Update GitHub Actions (#1094)
Expand Down
38 changes: 0 additions & 38 deletions src/structures/generic/matrix.cpp

This file was deleted.

23 changes: 17 additions & 6 deletions src/structures/generic/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All rights reserved (see LICENSE).
*/

#include <initializer_list>
#include <vector>

#include "structures/typedefs.h"

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

public:
Matrix();
Matrix() : Matrix(0) {
}

explicit Matrix(std::size_t n);
explicit Matrix(std::size_t n) : Matrix(n, 0) {
}

Matrix(std::size_t n, T value);
Matrix(std::size_t n, T value) : n(n), data(n * n, value) {
}

Matrix<T> get_sub_matrix(const std::vector<Index>& indices) const;
Matrix<T> get_sub_matrix(const std::vector<Index>& indices) const {
Matrix<T> sub_matrix(indices.size());
for (std::size_t i = 0; i < indices.size(); ++i) {
for (std::size_t j = 0; j < indices.size(); ++j) {
sub_matrix[i][j] = (*this)[indices[i]][indices[j]];
}
}
return sub_matrix;
}

T* operator[](std::size_t i) {
return data.data() + (i * n);
Expand All @@ -44,7 +55,7 @@ template <class T> class Matrix {
#if USE_PYTHON_BINDINGS
T* get_data() {
return data.data();
};
}
#endif
};

Expand Down

0 comments on commit 2ead5cc

Please sign in to comment.