-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmult.c
40 lines (32 loc) · 1016 Bytes
/
mmult.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* An unoptimized implementation of matrix multiplication.
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "mat.h"
/**
* An unoptimized algorithm for matrix multiplication.
*
* @param c : the matrix in which to place the result of the matrix multiplication.
* @param a : the first matrix.
* @param aRows : the number of rows in a.
* @param aCols : the number of columns in a.
* @param b : the second matrix.
* @param bRows : the number of rows in b.
* @param bCols : the number of columns in b.
* @return 0 if the matrix multiplication is successful.
*/
int mmult(double *c,
double *a, int aRows, int aCols,
double *b, int bRows, int bCols) {
for(int i = 0; i < aRows; ++i) {
for(int j = 0; j < bCols; ++j) {
c[i * bCols + j] = 0;
for(int k = 0; k < aRows; ++k) {
c[i * bCols + j] += a[i * aRows + k] * b[k * bCols + j];
}
}
}
return 0;
}