add_to_matrix#

Calculates \(\boldsymbol{C}= \boldsymbol{C} + \boldsymbol{A}\) if dimensions of \(\boldsymbol{A}\) and \(\boldsymbol{C}\) are equal.

void uz_matrix_add(uz_matrix_t const *const A, uz_matrix_t *const C_out)#

Calculates C_out += A.

Parameters:
  • A – Pointer to a uz_matrix_t instance

  • C_out – Adds the values of A to C_out

Example#

\[\begin{split}\begin{bmatrix} 1 & 2\\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 1 & 2\\ 3 & 4 \end{bmatrix} = \begin{bmatrix} 2 & 4\\ 6 & 8 \end{bmatrix}\end{split}\]
 1
 2void test_uz_matrix_add_to_matrix_2_times2(void){
 3    uint32_t rows=2;
 4    uint32_t columns=2;
 5    float A_data[4]={1,2,3,4};
 6    float C_data[4]={1,2,3,4};
 7    uz_matrix_t* A=init_array_test_helper(A_data,UZ_MATRIX_SIZE(A_data),rows, columns );
 8    uz_matrix_t* C=init_array_test_helper(C_data,UZ_MATRIX_SIZE(C_data),rows, columns );
 9    // C=A + B
10    uz_matrix_add(A,C);
11    TEST_ASSERT_EQUAL_FLOAT(2,uz_matrix_get_element_zero_based(C,0,0) );
12    TEST_ASSERT_EQUAL_FLOAT(4,uz_matrix_get_element_zero_based(C,0,1) );
13    TEST_ASSERT_EQUAL_FLOAT(6,uz_matrix_get_element_zero_based(C,1,0) );
14    TEST_ASSERT_EQUAL_FLOAT(8,uz_matrix_get_element_zero_based(C,1,1) );