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