A lightweight, minimal C++ library for matrix abstractions, arithmetic, and analytical utilities.
matxlib-cpp is a header-only matrix library built in C++. It's written from scratch as a personal project to understand how such libraries work under the hood. It supports basic matrix creation, manipulation, and arithmetic, descriptive and statistical operations.
π Features
- π Matrix Construction: basic creation, initialization, and memory management
- β Arithmetic Operations: element-wise and scalar operations (add, subtract, multiply, divide)
- π Descriptive Statistics: mean, min, max, sum, and other aggregations
- π Transformations: transpose, sparse matrix representation, etc.
- π§ Utility Functions: clean utility wrappers, macros and ERROR_CODES.
- π¨οΈ Input/Output: easy matrix display and input
- π Modular Design: every operation is split into clear, reusable headers
- βοΈ Self-contained: no external dependencies
- C++ Compiler with support for C++11 or higher (e.g., g++, clang++, or MSVC)
- Make (optional) if using the provided Makefile
- Git to clone the repository (or download ZIP manually)
No external libraries or dependencies are required β itβs built with standard C++ only.
-
Open your terminal (or command prompt).
-
Navigate to the directory where you want to place the project (e.g., Desktop).
cd ~/Desktop
-
Paste the following command in the terminal (or command prompt):
git clone https://github.com/manakcodes/matxlib-cpp.git
-
Include the following header in your C++ program to use the library (or adjust the path accordingly).
#include "matxlib-cpp/matxlib.hpp"
-
You can use the library in your C++ programs like you normally do in any code editor or IDE (e.g., VSCode, CLion, Vim, Atom etc.).
After the first-time setup, follow these steps each time you use the library in a new C++ project:
-
Make sure your project file (e.g., your_file.cpp) is in the same directory level or you correctly reference the path to the library (or adjust the path accordingly).
-
Include the following header:
#include "matxlib-cpp/matxlib.hpp"
-
Compile with g++ or your preferred compiler. If needed, link any required flags or paths:
g++ main.cpp -o main
./main
-
Youβre good to go !
#include "matxlib-cpp/matxlib.hpp"
int main() {
size_t rows = 3;
size_t cols = 3;
MATRIX* m = new MATRIX(rows, cols);
m->RandomizeMatrixInt(1, 10);
m->PrintMatrix();
delete m;
return 0;
}+------------+------------+------------+
| 5.0000 | 1.0000 | 6.0000 |
+------------+------------+------------+
| 5.0000 | 9.0000 | 6.0000 |
+------------+------------+------------+
| 7.0000 | 8.0000 | 10.0000 |
+------------+------------+------------+more examples soon to be added in a dedicated examples/ folder.
I built matxlib-cpp simply because I wanted to create my own matrix library from scratch - as a fun learning project to explore C++ and better understand how things work under the hood.
.
βββ assets # <-- ASCII art, configuration macros, and images
β βββ configurations.hpp
β βββ details.hpp
β βββ matxlib-cpp-ascii.jpg
β βββ matxlib-cpp.jpg
βββ include # <-- core library headers
β βββ arithmetic # <-- arithmetic operations on matrices
β β βββ add_a_scalar_to_matrix.hpp
β β βββ add_matrix.hpp
β β βββ divide_matrix_by_a_scalar.hpp
β β βββ multiply_matrix_by_a_scalar.hpp
β β βββ multiply_matrix_element_wise.hpp
β β βββ multiply_matrix.hpp
β β βββ subtract_matrix.hpp
β β βββ subtract_scalar_from_matrix.hpp
β βββ core # <-- MATRIX class, ctor/dtor, accessors, etc
β β βββ class.hpp
β β βββ constructor.hpp
β β βββ destructor.hpp
β β βββ error_codes.hpp
β β βββ getters_and_setters.hpp
β βββ descriptive # <-- descriptive statistics and summaries
β β βββ descriptive_methods.hpp
β βββ io # <-- Input/Output utilities
β β βββ input_output_matrix.hpp
β βββ statistics # <-- statistical functions
β β βββ statistics_methods.hpp
β βββ transforms # <-- MATRIX transformations
β β βββ sparse_matrix.hpp
β β βββ transpose_matrix.hpp
β βββ utility # <-- miscellaneous utilities
β βββ utility_matrix.hpp
βββ LICENSE # <-- LICENSE
βββ Main.cpp # <-- Main
βββ Makefile # <-- Makefile
βββ matxlib.hpp # <-- ** MAIN INCLUDE HEADER **
βββ README.md # <-- you are here :)
βββ test.cpp # <-- tester file
10 directories, 28 filesThis project is licensed under the MIT License - see LICENSE for details.
