/// @file /// @brief Task2: function definitions #include "task2.h" // struct Matrix, matrix_mult #include // size_t #include // printf #include // malloc, free /// @todo Include C standard library headers as needed /// @note This implementation is provided as declared and specified in task2.h struct Matrix matrix_init(size_t m, size_t n, const double* data) { struct Matrix res = {.data = malloc(sizeof(double) * m * n), .m = m, .n = n}; double* A = res.data; for (size_t i = 0; i != m * n; ++i) A[i] = data[i]; return res; } /// @note This implementation is provided as declared and specified in task2.h void matrix_print(const struct Matrix* mat) { size_t M = mat->m; size_t N = mat->n; const double* A = mat->data; for (size_t m = 0; m != M; ++m) { for (size_t n = 0; n != N; ++n) printf("%lf ", A[n + N * m]); printf("\n"); } printf("\n"); } /// @note This implementation is provided as declared and specified in task2.h void matrix_clear(struct Matrix* mat) { free(mat->data); mat->m = 0; mat->n = 0; } /// @todo Implement function 'matrix_zeros' as declared and specified in task2.h struct Matrix matrix_zeros(size_t m, size_t n) { return (struct Matrix){.data = NULL, .m = 0, .n = 0}; } /// @todo Implement function 'matrix_identity' as declared and specified in task2.h struct Matrix matrix_identity(size_t n) { return (struct Matrix){.data = NULL, .m = 0, .n = 0}; } /// @todo Implement function 'matrix_transpose' as declared and specified in task2.h void matrix_transpose(struct Matrix* a) {} /// @todo Implement function 'matrix_mult' as declared and specified in task2.h void matrix_mult(const struct Matrix* a, const struct Matrix* b, struct Matrix* c) {}