A lightweight C++ tensor library implementing core PyTorch-like operations for CPU. Designed as a minimal foundation for building neural networks without the complexity of full frameworks.
Tensor Operations
- N-dimensional tensor data structure with automatic stride calculation
- Element-wise operations (add, sub, mul, div, neg, exp, log, pow, clamp) with NumPy-style broadcasting
- Matrix multiplication with batch dimension support
- Reductions: sum, mean, variance, argmax, softmax
- Reshape, transpose, cat, stack, slice, pad
Neural Network Modules
- Linear, LayerNorm, Dropout
- MultiHeadAttention, TransformerEncoderLayer, TransformerEncoder
- PositionalEncoding
- Activation functions: ReLU, GELU, Sigmoid
Design
- CPU-only, float32 operations
- Weight loading from raw binary files
Build the library:
mkdir build && cd build
cmake ..
makeRun tests:
./build/run_testsinclude/tl/ Public API headers (tensor, ops, nn, activation, factory)
include/external/ Third-party headers (LibrosaCpp)
src/ Implementation
tests/ Test executables
- Eigen3: required by LibrosaCpp for audio preprocessing
- LibrosaCpp: single-header mel spectrogram computation (included in
include/external/)
- C++17 or later
- CMake 3.10+
- Eigen3 (
sudo apt install libeigen3-dev)
MIT License