change indices from col,row to row,col
This commit is contained in:
parent
1d56c491d4
commit
0751b7734c
10
matrix.hpp
10
matrix.hpp
@ -29,14 +29,16 @@ template <class T> struct Matrix {
|
||||
|
||||
for (std::uint32_t i = 0; i < rows; i++) {
|
||||
for (std::uint32_t j = 0; j < cols; j++) {
|
||||
matfs >> (*this)(j, i);
|
||||
matfs >> (*this)(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
this->rows = mat.rows;
|
||||
@ -50,7 +52,7 @@ template <class T> struct Matrix {
|
||||
Matrix<T> transposed = *this;
|
||||
for (std::uint32_t i = 0; i < this->rows; i++) {
|
||||
for (std::uint32_t j = 0; j < this->cols; j++) {
|
||||
transposed(i, j) = (*this)(j, i);
|
||||
transposed(j, i) = (*this)(i, j);
|
||||
}
|
||||
}
|
||||
return transposed;
|
||||
@ -62,7 +64,7 @@ template <class T> struct Matrix {
|
||||
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 j = 0; j < mat.cols; j++) {
|
||||
os << mat(j, i) << "\t";
|
||||
os << mat(i, j) << "\t";
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user