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