diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 0e4c4c3..2d4b787 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -57,11 +57,21 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) newmatrix.buffer = malloc(newmatrix.cols * newmatrix.rows * sizeof(MatrixType)); for(int i = 0; i < matrix1.rows; i++){ for(int j = 0; j < matrix1.cols; j++){ - //printf("Added %f to get %f\n", *(matrix2.buffer+i*matrix2.cols), *(matrix1.buffer+i*matrix1.cols+j) + *(matrix2.buffer+i*matrix2.cols)); *(newmatrix.buffer+i*newmatrix.cols+j) = *(matrix1.buffer+i*matrix1.cols+j) + *(matrix2.buffer+i*matrix2.cols); } } } + else if(matrix1.cols == 1 && (matrix2.rows == matrix1.rows)){ + printf("Got broadcast\n"); + newmatrix.cols = matrix2.cols; + newmatrix.rows = matrix2.rows; + newmatrix.buffer = malloc(newmatrix.cols * newmatrix.rows * sizeof(MatrixType)); + for(int i = 0; i < matrix1.rows; i++){ + for(int j = 0; j < matrix2.cols; j++){ + *(newmatrix.buffer+i*newmatrix.cols+j) = *(matrix2.buffer+i*matrix2.cols+j) + *(matrix1.buffer+i*matrix1.cols); + } + } + } return newmatrix; }