Compare commits

..

No commits in common. "15d74d972db66c43c3a4ea2bfe84e219f6b38455" and "9bd18d3681be7febd1f9d8028fa8f7339a1cf777" have entirely different histories.

2 changed files with 6 additions and 2 deletions

View File

@ -147,6 +147,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
//size of the matrices should be the same, if the addition is supposed to happen //size of the matrices should be the same, if the addition is supposed to happen
// Matrix outputMatrix = createMatrix(matrix1.rows, matrix1.cols);
Matrix outputMatrix = createMatrix(matrix1.rows, matrix1.cols); Matrix outputMatrix = createMatrix(matrix1.rows, matrix1.cols);
if(!outputMatrix.buffer){ if(!outputMatrix.buffer){
@ -211,12 +212,16 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
//Matrix outputMatrix = createMatrix(matrix2.cols, matrix1.rows); //Matrix outputMatrix = createMatrix(matrix2.cols, matrix1.rows);
for(int i = 0; i < matrix1.rows; i++) { for(int i = 0; i < matrix1.rows; i++) {
for (int j = 0; j < matrix2.cols; j++) { for (int j = 0; j < matrix2.cols; j++) {
MatrixType sum = 0;
for (int k = 0; k < matrix1.cols; k++) { for (int k = 0; k < matrix1.cols; k++) {
// how this should work in normal Matrix version: // how this should work in normal Matrix version:
// outputMatrix.buffer[i][j] = matrix1.buffer[i][k] * matrix2.buffer[k][j]; // outputMatrix.buffer[i][j] = matrix1.buffer[i][k] * matrix2.buffer[k][j];
//outputMatrix.buffer[i + outputMatrix.rows * j] += matrix1.buffer[i + matrix1.rows * k] * matrix2.buffer[k + matrix2.rows * j]; //outputMatrix.buffer[i + outputMatrix.rows * j] += matrix1.buffer[i + matrix1.rows * k] * matrix2.buffer[k + matrix2.rows * j];
outputMatrix.buffer[i * outputMatrix.cols + j] += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[j + matrix2.cols * k]; sum += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[j + matrix2.cols * k];
} }
outputMatrix.buffer[i * outputMatrix.cols + j] = sum;
} }
} }
return outputMatrix; return outputMatrix;

View File

@ -1 +0,0 @@
make clean && make matrixTests && ./runMatrixTests