2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
57 template<
typename T,
unsigned int R1,
unsigned int C1R2,
unsigned int C2>
58 void multiply(
Matrix<T, R1, C1R2> A,
Matrix<T, C1R2, C2> B,
Matrix<T, R1, C2> &result) {
74 for(i = 0; i < R1; i++) {
75 for(j = 0; j < C2; j++) {
76 result.values[i][j] = T();
79 for(k = 0; k < C1R2; k++) {
81 result.values[i][j] += A.values[i][k]*B.values[k][j];
92 template<
typename T,
unsigned int R,
unsigned int C>
93 void multiply(
const T &a,
Matrix<T, R, C> A,
Matrix<T, R, C> &result) {
105 for(i = 0; i < R; i++) {
106 for(j = 0; j < C; j++) {
107 result.values[i][j] = a*A.values[i][j];
117 template<
typename T,
unsigned int R,
unsigned int C>
130 for(i = 0; i < R; i++) {
131 for(j = 0; j < C; j++) {
132 result.values[i][j] = A.values[i][j]*B.values[i][j];
142 template<
typename T,
unsigned int R,
unsigned int C>
143 void add(
const T &a,
Matrix<T, R, C> A,
Matrix<T, R, C> &result) {
155 for(i = 0; i < R; i++) {
156 for(j = 0; j < C; j++) {
157 result.values[i][j] = a + A.values[i][j];
167 template<
typename T,
unsigned int R,
unsigned int C>
180 for(i = 0; i < R; i++) {
181 for(j = 0; j < C; j++) {
182 result.values[i][j] = A.values[i][j] + B.values[i][j];
192 template<
typename T,
unsigned int R,
unsigned int C>
205 for(i = 0; i < R; i++) {
206 for(j = 0; j < C; j++) {
207 result.values[i][j] = A.values[i][j] - B.values[i][j];
218 template<
typename T,
unsigned int R1,
unsigned int C1R2,
unsigned int C2>
219 Matrix<T, R1, C2> operator*(
const Matrix<T, R1, C1R2> &A,
const Matrix<T, C1R2, C2> &B) {
222 multiply(A, B, result);
228 template<
typename T,
unsigned int R,
unsigned int C>
229 Matrix<T, R, C> operator*(
const T &a,
const Matrix<T, R, C> &A) {
232 multiply(a, A, result);
235 template<
typename T,
unsigned int R,
unsigned int C>
236 Matrix<T, R, C> operator*(
const Matrix<T, R, C> &A,
const T &a) {
239 multiply(a, A, result);
245 template<
typename T,
unsigned int R,
unsigned int C>
255 template<
typename T,
unsigned int R,
unsigned int C>
256 Matrix<T, R, C> operator+(
const T &a,
const Matrix<T, R, C> &A) {
262 template<
typename T,
unsigned int R,
unsigned int C>
263 Matrix<T, R, C> operator+(
const Matrix<T, R, C> &A,
const T &a) {
271 template<
typename T,
unsigned int R,
unsigned int C>
275 eSubtract(A, B, result);
Matrix math implementation.
Definition Matrix.hpp:54