Fix row/col des matrices

This commit is contained in:
FyloZ 2024-01-29 14:27:22 -05:00
parent 92d337fcc6
commit 2a412ddb13
Signed by: william
GPG Key ID: 835378AE9AF4AE97
3 changed files with 22 additions and 42 deletions

View File

@ -66,7 +66,7 @@ namespace gti320 {
for (int col = 0; col < this->cols(); col++) {
for (int row = 0; row < this->rows(); row++) {
this(col, row) = submatrix(col, row);
this(row, col) = submatrix(row, col);
}
}
return *this;
@ -76,7 +76,7 @@ namespace gti320 {
* Accesseur à une entrée de la matrice (lecture seule)
*/
_Scalar operator()(int i, int j) const {
int index = i * this->rows() + j;
int index = i + j * this->rows();
return this->m_storage.data()[index];
}
@ -84,7 +84,7 @@ namespace gti320 {
* Accesseur à une entrée de la matrice (lecture ou écriture)
*/
_Scalar &operator()(int i, int j) {
int index = i * this->rows() + j;
int index = i + j * this->rows();
return this->m_storage.data()[index];
}
@ -111,7 +111,7 @@ namespace gti320 {
auto transposed = Matrix<_OtherScalar, _OtherRows, _OtherCols, _OtherStorage>(this->cols(), this->rows());
for (int col = 0; col < this->cols(); col++) {
for (int row = 0; row < this->rows(); row++) {
transposed(row, col) = (*this)(col, row);
transposed(col, row) = (*this)(row, col);
}
}
return transposed;
@ -172,7 +172,7 @@ namespace gti320 {
for (int row = 0; row < this->rows(); row++) {
for (int col = 0; col < this->cols(); col++) {
this(col, row) = submatrix(col, row);
this(row, col) = submatrix(row, col);
}
}
return *this;
@ -182,7 +182,7 @@ namespace gti320 {
* Accesseur à une entrée de la matrice (lecture seule)
*/
_Scalar operator()(int i, int j) const {
int index = i + j * this->cols();
int index = i * this->cols() + j;
return this->m_storage.data()[index];
}
@ -190,7 +190,7 @@ namespace gti320 {
* Accesseur à une entrée de la matrice (lecture ou écriture)
*/
_Scalar &operator()(int i, int j) {
int index = i + j * this->cols();
int index = i * this->cols() + j;
return this->m_storage.data()[index];
}
@ -217,7 +217,7 @@ namespace gti320 {
for (int row = 0; row < this->rows(); row++) {
for (int col = 0; col < this->cols(); col++) {
t(row, col) = (*this)(col, row);
t(col, row) = (*this)(row, col);
}
}
@ -310,7 +310,7 @@ namespace gti320 {
for (int col = 0; col < this->cols(); col++) {
for (int row = 0; row < this->rows(); row++) {
(*this)(col, row) = matrix(col, row);
(*this)(row, col) = matrix(row, col);
}
}
@ -362,7 +362,7 @@ namespace gti320 {
for (int col = 0; col < this->cols(); col++) {
for (int row = 0; row < this->rows(); row++) {
t(row, col) = (*this)(col, row);
t(col, row) = (*this)(row, col);
}
}

View File

@ -32,7 +32,7 @@ namespace gti320 {
for (int col = 0; col < B.cols(); col++) {
for (int row = 0; row < A.rows(); row++) {
for (int k = 0; k < A.cols(); k++) {
result(col, row) += A(k, row) * B(col, k);
result(row, col) += A(row, k) * B(k, col);
}
}
}
@ -57,7 +57,7 @@ namespace gti320 {
for (int col = 0; col < A.cols(); col++) {
for (int row = 0; row < B.rows(); row++) {
for (int k = 0; k < B.cols(); k++) {
result(k, row) += A(col, row) * B(k, col);
result(row, k) += A(row, col) * B(col, k);
}
}
}
@ -82,7 +82,7 @@ namespace gti320 {
for (int col = 0; col < B.cols(); col++) {
for (int row = 0; row < A.rows(); row++) {
for (int k = 0; k < A.cols(); k++) {
result(col, row) += A(k, row) * B(col, k);
result(row, col) += A(row, k) * B(k, col);
}
}
}
@ -127,7 +127,7 @@ namespace gti320 {
for (int col = 0; col < A.cols(); col++) {
for (int row = 0; row < A.rows(); row++) {
result(row, col) = A(row, col) + B(row, col);
result(col, row) = A(col, row) + B(col, row);
}
}

View File

@ -224,31 +224,11 @@ TEST(TestLabo1, MatrixMatrixOperators) {
{
// Création d'un matrice à stockage par lignes
Matrix<double, Dynamic, Dynamic, RowStorage> A(5, 5);
A(0, 0) = 0.8147;
A(0, 1) = 0.0975;
A(0, 2) = 0.1576;
A(0, 3) = 0.1419;
A(0, 4) = 0.6557;
A(1, 0) = 0.9058;
A(1, 1) = 0.2785;
A(1, 2) = 0.9706;
A(1, 3) = 0.4218;
A(1, 4) = 0.0357;
A(2, 0) = 0.1270;
A(2, 1) = 0.5469;
A(2, 2) = 0.9572;
A(2, 3) = 0.9157;
A(2, 4) = 0.8491;
A(3, 0) = 0.9134;
A(3, 1) = 0.9575;
A(3, 2) = 0.4854;
A(3, 3) = 0.7922;
A(3, 4) = 0.9340;
A(4, 0) = 0.6324;
A(4, 1) = 0.9649;
A(4, 2) = 0.8003;
A(4, 3) = 0.9595;
A(4, 4) = 0.6787;
A(0, 0) = 0.8147; A(0, 1) = 0.0975; A(0, 2) = 0.1576; A(0, 3) = 0.1419; A(0, 4) = 0.6557;
A(1, 0) = 0.9058; A(1, 1) = 0.2785; A(1, 2) = 0.9706; A(1, 3) = 0.4218; A(1, 4) = 0.0357;
A(2, 0) = 0.1270; A(2, 1) = 0.5469; A(2, 2) = 0.9572; A(2, 3) = 0.9157; A(2, 4) = 0.8491;
A(3, 0) = 0.9134; A(3, 1) = 0.9575; A(3, 2) = 0.4854; A(3, 3) = 0.7922; A(3, 4) = 0.9340;
A(4, 0) = 0.6324; A(4, 1) = 0.9649; A(4, 2) = 0.8003; A(4, 3) = 0.9595; A(4, 4) = 0.6787;
// Test : transposée (le résultat est une matrice à stockage par
// colonnes)
@ -598,7 +578,7 @@ TEST(TestLabo1, Supplementaires) {
expected = 1;
}
EXPECT_EQ(MC(col, row), expected);
EXPECT_EQ(MC(row, col), expected);
}
}
@ -632,7 +612,7 @@ TEST(TestLabo1, Supplementaires) {
MC(1, 0) = 5;
MC(0, 1) = 6;
EXPECT_EQ(MC.data()[0], MC(0, 0));
EXPECT_EQ(MC.data()[1], MC(0, 1));
EXPECT_EQ(MC.data()[1], MC(1, 0));
// Test 9: Stockage par rangée
Matrix<int, -1, -1, RowStorage> MS(4, 6);
@ -640,7 +620,7 @@ TEST(TestLabo1, Supplementaires) {
MS(1, 0) = 5;
MS(0, 1) = 6;
EXPECT_EQ(MS.data()[0], MS(0, 0));
EXPECT_EQ(MS.data()[1], MS(1, 0));
EXPECT_EQ(MS.data()[1], MS(0, 1));
// === Vecteurs ===
// Test 10: Copie