forked from freudenreichan/info2Praktikum-NeuronalesNetz
matrix.c unitTest PASS
This commit is contained in:
parent
da8dc2a9ef
commit
9e7fcca725
11
matrix.c
11
matrix.c
@ -56,7 +56,11 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
Matrix result = {0};
|
Matrix result = {0};
|
||||||
|
|
||||||
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
int broadcast_case =
|
||||||
|
(matrix1.cols == 1 && matrix1.rows == matrix2.rows) ||
|
||||||
|
(matrix2.cols == 1 && matrix1.rows == matrix2.rows);
|
||||||
|
|
||||||
|
if (!broadcast_case && (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols))
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -75,6 +79,8 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
|
|
||||||
if (matrix1.cols == 1 && matrix1.rows == matrix2.rows) // Broadcasting
|
if (matrix1.cols == 1 && matrix1.rows == matrix2.rows) // Broadcasting
|
||||||
{
|
{
|
||||||
|
result.rows = matrix2.rows;
|
||||||
|
result.cols = matrix2.cols;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < matrix1.rows; i++)
|
for (unsigned int i = 0; i < matrix1.rows; i++)
|
||||||
{
|
{
|
||||||
@ -89,6 +95,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
|
|
||||||
else if (matrix2.cols == 1 && matrix1.rows == matrix2.rows)
|
else if (matrix2.cols == 1 && matrix1.rows == matrix2.rows)
|
||||||
{
|
{
|
||||||
|
result.rows = matrix1.rows;
|
||||||
|
result.cols = matrix1.cols;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < matrix2.rows; i++)
|
for (unsigned int i = 0; i < matrix2.rows; i++)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < result.cols; j++)
|
for (unsigned int j = 0; j < result.cols; j++)
|
||||||
|
|||||||
BIN
runMatrixTests
BIN
runMatrixTests
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user