change indices from col,row to row,col

This commit is contained in:
Max Lübke 2023-10-02 11:18:08 +02:00
parent 1d56c491d4
commit 0751b7734c

View File

@ -29,14 +29,16 @@ template <class T> struct Matrix {
for (std::uint32_t i = 0; i < rows; i++) { for (std::uint32_t i = 0; i < rows; i++) {
for (std::uint32_t j = 0; j < cols; j++) { for (std::uint32_t j = 0; j < cols; j++) {
matfs >> (*this)(j, i); matfs >> (*this)(i, j);
} }
} }
matfs.close(); matfs.close();
} }
T &operator()(std::uint32_t x, std::uint32_t y) { return data[y * cols + x]; } T &operator()(std::uint32_t row_i, std::uint32_t col_j) {
return data[row_i * cols + col_j];
}
Matrix<T> &operator=(const Matrix<T> &mat) { Matrix<T> &operator=(const Matrix<T> &mat) {
this->rows = mat.rows; this->rows = mat.rows;
@ -50,7 +52,7 @@ template <class T> struct Matrix {
Matrix<T> transposed = *this; Matrix<T> transposed = *this;
for (std::uint32_t i = 0; i < this->rows; i++) { for (std::uint32_t i = 0; i < this->rows; i++) {
for (std::uint32_t j = 0; j < this->cols; j++) { for (std::uint32_t j = 0; j < this->cols; j++) {
transposed(i, j) = (*this)(j, i); transposed(j, i) = (*this)(i, j);
} }
} }
return transposed; return transposed;
@ -62,7 +64,7 @@ template <class T> struct Matrix {
template <class T> std::ostream &operator<<(std::ostream &os, Matrix<T> &mat) { template <class T> std::ostream &operator<<(std::ostream &os, Matrix<T> &mat) {
for (std::uint32_t i = 0; i < mat.rows; i++) { for (std::uint32_t i = 0; i < mat.rows; i++) {
for (std::uint32_t j = 0; j < mat.cols; j++) { for (std::uint32_t j = 0; j < mat.cols; j++) {
os << mat(j, i) << "\t"; os << mat(i, j) << "\t";
} }
os << "\n"; os << "\n";
} }