Line data Source code
1 : /* 2 : * N dimensional matrix operations 3 : */ 4 : 5 : #pragma GCC optimize("O2") 6 : 7 : #include "matrixN.h" 8 : 9 : 10 : // multiply two vectors to give a matrix, in-place 11 : template <typename T, uint8_t N> 12 13618 : void MatrixN<T,N>::mult(const VectorN<T,N> &A, const VectorN<T,N> &B) 13 : { 14 68090 : for (uint8_t i = 0; i < N; i++) { 15 272360 : for (uint8_t j = 0; j < N; j++) { 16 217888 : v[i][j] = A[i] * B[j]; 17 : } 18 : } 19 13618 : } 20 : 21 : // subtract B from the matrix 22 : template <typename T, uint8_t N> 23 13618 : MatrixN<T,N> &MatrixN<T,N>::operator -=(const MatrixN<T,N> &B) 24 : { 25 68090 : for (uint8_t i = 0; i < N; i++) { 26 272360 : for (uint8_t j = 0; j < N; j++) { 27 217888 : v[i][j] -= B.v[i][j]; 28 : } 29 : } 30 13618 : return *this; 31 : } 32 : 33 : // add B to the matrix 34 : template <typename T, uint8_t N> 35 13618 : MatrixN<T,N> &MatrixN<T,N>::operator +=(const MatrixN<T,N> &B) 36 : { 37 68090 : for (uint8_t i = 0; i < N; i++) { 38 272360 : for (uint8_t j = 0; j < N; j++) { 39 217888 : v[i][j] += B.v[i][j]; 40 : } 41 : } 42 13618 : return *this; 43 : } 44 : 45 : // Matrix symmetry routine 46 : template <typename T, uint8_t N> 47 13618 : void MatrixN<T,N>::force_symmetry(void) 48 : { 49 68090 : for (uint8_t i = 0; i < N; i++) { 50 95326 : for (uint8_t j = 0; j < (i - 1); j++) { 51 40854 : v[i][j] = (v[i][j] + v[j][i]) / 2; 52 40854 : v[j][i] = v[i][j]; 53 : } 54 : } 55 13618 : } 56 : 57 : template void MatrixN<float,4>::mult(const VectorN<float,4> &A, const VectorN<float,4> &B); 58 : template MatrixN<float,4> &MatrixN<float,4>::operator -=(const MatrixN<float,4> &B); 59 : template MatrixN<float,4> &MatrixN<float,4>::operator +=(const MatrixN<float,4> &B); 60 : template void MatrixN<float,4>::force_symmetry(void);