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 files
This project is licensed under the MIT License - see LICENSE for details.