The project revolved around the construction of a dedicated library, named matrix.h, for performing operations on numerical matrices using the C programming language. Matrices hold a fundamental position in programming, serving functions from representing data in tabular form to being core elements in computational tasks, including neural networks.
git clone https://github.com/0xmisha/matrix.h.git
cd matrix.h/src
make
- Gcc
- Make
- check.h (for tests)
A structure matrix_t was designed to represent matrices:
typedef struct matrix_struct {
double** matrix;
int rows;
int columns;
} matrix_t;This structure includes a double pointer to represent the matrix and two integers specifying its dimensions.
Several vital matrix operations were implemented:
- Creation:
create_matrixinitializes a matrix with specified rows and columns. - Deletion:
remove_matrixcleans up and de-allocates a matrix. - Comparison:
eq_matrixdetermines the equality of two matrices. - Addition & Subtraction:
sum_matrixandsub_matrixhandle matrix arithmetic. - Scalar & Matrix Multiplication:
mult_numberscales a matrix, whilemult_matrixmanages matrix-to-matrix multiplication. - Transpose:
transposereturns the transpose of a matrix. - Algebraic Complements:
calc_complementscomputes the matrix of algebraic complements. - Determinant:
determinantevaluates the determinant of a matrix. - Matrix Inversion:
inverse_matrixfinds the inverse of a matrix.
Every function, except for eq_matrix, returns specific codes indicating successful operation or a particular error type.
- Language & Compiler: The library adheres to the C11 standard and is compiled using
gcc. - Code Location: The source code resides in the
srcfolder on thedevelopbranch. - Coding Standards: Legacy constructs were avoided, ensuring compliance with the POSIX.1-2017 standard. The Google style was followed throughout development.
- Library Type: The matrix library is static, complemented by the
matrix.hheader file. - Function Naming: Each function is prefixed to maintain naming clarity.
- Unit Testing: Comprehensive unit-tests were designed using the Check library, targeting at least 80% coverage per function.
gcovwas employed to monitor this metric. - Compilation & Testing: A Makefile, complete with targets (
all,clean,test,matrix.a,gcov_report), facilitates building and testing operations. Specifically,gcov_reportgenerates an HTML-based coverage report. - Precision: The library guarantees accuracy up to six decimal places for fractional components.
This endeavor successfully distilled the essence of matrix operations, fortified by rigorous development standards, into a robust C library.