Skip to content

Commit f4c49e9

Browse files
committed
Fix matrix row and column mixup
m_matrix elements point to the rows, so the first index should be related to the height, and the second index to the width. It does end up working without this fix, because the matrix width is constrained to be 1 in both vectorMagnitudeSquared() and dot(), and the matrix elements are stored consecutively, in one array, so the memory accesses are exactly the same in both cases. So, this is mostly a cosmetic fix (ATM), but can help with understanding the code.
1 parent af0a00d commit f4c49e9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ double atg_scs::Matrix::vectorMagnitudeSquared() const {
231231

232232
double mag = 0;
233233
for (int i = 0; i < m_height; ++i) {
234-
mag += m_matrix[0][i] * m_matrix[0][i];
234+
mag += m_matrix[i][0] * m_matrix[i][0];
235235
}
236236

237237
return mag;
@@ -244,7 +244,7 @@ double atg_scs::Matrix::dot(Matrix &b) const {
244244

245245
double result = 0;
246246
for (int i = 0; i < m_height; ++i) {
247-
result += m_matrix[0][i] * b.m_matrix[0][i];
247+
result += m_matrix[i][0] * b.m_matrix[i][0];
248248
}
249249

250250
return result;

0 commit comments

Comments
 (0)