MLib is a performant linear algebra library implemented in C with a Python interface, featuring key matrix operations and automatic differentiation capabilities. It’s designed for numerical computing and machine learning tasks, providing matrix functions optimized for speed and an intuitive Python API.
- Essential matrix operations: addition, subtraction, multiplication, division, exponentiation, logarithm, exponentials, transpose, reshape, and more.
- Optimized matrix multiplication for 2D arrays.
- Matrix inversion for square positive semi-definite matrices.
- Views and slicing with shared memory support.
- Random vector/matrix generation with flexible bounds.
- Built-in automatic differentiation (autograd) for gradient computation.
- High-performance C backend with Python bindings.
To build the C library, use the provided Makefile:
makeClean build artifacts with:
make cleanMLib’s tutorial.ipynb notebook contains a comprehensive, step-by-step tutorial with examples on basic operations, benchmarking performance, and practical use cases like linear regression. It is highly recommended to start there for a guided introduction.
If you don’t have it installed, you may need to install matplotlib for plotting in the tutorial:
pip3 install matplotlibMLib significantly outperforms vanilla Python list operations in element-wise matrix computations, making it suitable for large scale numerical tasks.
Run the unit tests to verify the installation:
python3 -m unittest discover -s testsThe project draws from foundational and practical resources including:
- LU Decomposition - Wikipedia
- PyTorch Internals - E. Z. Yang
- Recreating PyTorch from Scratch - Towards Data Science
- DIY Autograd Engine - Medium
- Matrix differentiation notes by Randal J. Barnes, University of Minnesota
- NumPy Internals
For an in-depth introduction, code examples, and use cases, please see the tutorial.ipynb included in this repository. It provides a clearer, interactive walkthrough of MLib’s capabilities.
This project is licensed under the MIT License. See LICENSE for details.
Thank you for exploring MLib!
Happy computing.