Browse Source

Cache-oblivious traversing order in Matrix functions.

Loop through all cols, then rows, so the memory is accessed
continuously.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
391e721ac6
  1. 9
      src/Math/Matrix.h
  2. 4
      src/Math/RectangularMatrix.h

9
src/Math/Matrix.h

@ -38,7 +38,6 @@ See @ref matrix-vector for brief introduction.
@configurationvalueref{Magnum::Math::Matrix}
@todo @c PERFORMANCE - loop unrolling for Matrix<3, T> and Matrix<4, T>
@todo first col, then row (cache adjacency)
*/
template<size_t s, class T> class Matrix: public RectangularMatrix<s, s, T> {
public:
@ -104,8 +103,8 @@ template<size_t s, class T> class Matrix: public RectangularMatrix<s, s, T> {
Matrix<size-1, T> ij(size_t skipCol, size_t skipRow) const {
Matrix<size-1, T> out(Matrix<size-1, T>::Zero);
for(size_t row = 0; row != size-1; ++row)
for(size_t col = 0; col != size-1; ++col)
for(size_t col = 0; col != size-1; ++col)
for(size_t row = 0; row != size-1; ++row)
out(col, row) = (*this)(col + (col >= skipCol),
row + (row >= skipRow));
@ -137,8 +136,8 @@ template<size_t s, class T> class Matrix: public RectangularMatrix<s, s, T> {
T _determinant = determinant();
for(size_t row = 0; row != size; ++row)
for(size_t col = 0; col != size; ++col)
for(size_t col = 0; col != size; ++col)
for(size_t row = 0; row != size; ++row)
out(col, row) = (((row+col) & 1) ? -1 : 1)*ij(row, col).determinant()/_determinant;
return out;

4
src/Math/RectangularMatrix.h

@ -281,8 +281,8 @@ template<size_t c, size_t r, class T> class RectangularMatrix {
template<size_t size> RectangularMatrix<size, rows, T> operator*(const RectangularMatrix<size, cols, T>& other) const {
RectangularMatrix<size, rows, T> out;
for(size_t row = 0; row != rows; ++row)
for(size_t col = 0; col != size; ++col) /** @todo swap */
for(size_t col = 0; col != size; ++col)
for(size_t row = 0; row != rows; ++row)
for(size_t pos = 0; pos != cols; ++pos)
out(col, row) += (*this)(pos, row)*other(col, pos);

Loading…
Cancel
Save