forked from freudenreichan/info2Praktikum-NeuronalesNetz
matrixAdd check
This commit is contained in:
parent
07f217f1f4
commit
da8dc2a9ef
38
matrix.c
38
matrix.c
@ -73,14 +73,44 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Matritzenaddition
|
||||
for (unsigned int i = 0; i < result.rows; i++)
|
||||
if (matrix1.cols == 1 && matrix1.rows == matrix2.rows) // Broadcasting
|
||||
{
|
||||
for (unsigned int j = 0; j < result.cols; j++)
|
||||
|
||||
for (unsigned int i = 0; i < matrix1.rows; i++)
|
||||
{
|
||||
result.buffer[i * result.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix2.cols + j];
|
||||
for (unsigned int j = 0; j < result.cols; j++)
|
||||
{
|
||||
result.buffer[i * result.cols + j] = matrix1.buffer[i] + matrix2.buffer[i * matrix2.cols + j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if (matrix2.cols == 1 && matrix1.rows == matrix2.rows)
|
||||
{
|
||||
for (unsigned int i = 0; i < matrix2.rows; i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < result.cols; j++)
|
||||
{
|
||||
result.buffer[i * result.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Elementweise Addition
|
||||
for (unsigned int i = 0; i < result.rows; i++)
|
||||
{
|
||||
for (unsigned int j = 0; j < result.cols; j++)
|
||||
{
|
||||
result.buffer[i * result.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix2.cols + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BIN
runMatrixTests
BIN
runMatrixTests
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user