52 lines
2.1 KiB
C
52 lines
2.1 KiB
C
/// @file
|
|
/// @brief Task2: Structure definitions and function declarations
|
|
|
|
#pragma once
|
|
|
|
#include <stddef.h> // size_t
|
|
|
|
/// @brief Two-dimensional matrix with 'm' rows and 'n' columns.
|
|
/// @note: the values ares stored in a contiguous block in memory in row-major layout
|
|
/// @note: row-major storage order is used, access of element (i,j) -> data[j + n*i]
|
|
struct Matrix {
|
|
double* data; ///< pointer to a dynamically allocated contiguous memory block fitting m*n values
|
|
size_t m; ///< number of rows (first dimension)
|
|
size_t n; ///< number of columns (second dimension)
|
|
};
|
|
|
|
/// @brief Initalize a matrix from the values in a buffer
|
|
/// @param m first dimension of the matrix
|
|
/// @param n second dimension of the matrix
|
|
/// @param data contiguous memory holding the values to copy (in row-major format)
|
|
struct Matrix matrix_init(size_t m, size_t n, const double* data);
|
|
|
|
/// @brief Prints a Matrix to the console
|
|
/// @param mat Matrix to be printed
|
|
void matrix_print(const struct Matrix* mat);
|
|
|
|
/// @brief Resets a matrix (deallocates memory and sets its size to 0 x 0)
|
|
/// @param mat Matrix to be reset
|
|
void matrix_clear(struct Matrix* mat);
|
|
|
|
/// @brief Initializes an matrix with zeros
|
|
/// @param m first dimension of the matrix
|
|
/// @param n first dimension of the matrix
|
|
struct Matrix matrix_zeros(size_t m, size_t n);
|
|
|
|
/// @brief Initializes a square identity matrix
|
|
/// @param n dimension of the identity matrix
|
|
struct Matrix matrix_identity(size_t n);
|
|
|
|
/// @brief Transposes a matrix
|
|
/// @param mat Matrix to be transposed
|
|
/// @note this function might swap/replace the block of memory owned by the matrix
|
|
void matrix_transpose(struct Matrix* mat);
|
|
|
|
/// @brief Performs a matrix-matrix mutliplication: a*b = c
|
|
/// @a first matrix (left factor)
|
|
/// @b second matrix (right factor)
|
|
/// @c Result of the multiplication is stored in this Matrix:
|
|
/// - the dimensions of this matrix must be 'a.m x b.n' when calling this function
|
|
/// - the values will be overwritten with the result of the multiplication
|
|
void matrix_mult(const struct Matrix* a, const struct Matrix* b, struct Matrix* c);
|