Implemented broadcasting
This commit is contained in:
1 parent
bc87e13966
commit
f1556b18ba
1 file changed
+11
-1
+11
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user