apoorvnandan/tensor.h
Freecreating a tiny tensor library in raw C
FreeFree tier
About apoorvnandan/tensor.h
tensor.h is a tiny tensor library written entirely in raw C, created to help developers understand neural networks from absolute scratch. It provides minimal abstractions for tensor operations, autograd, loss functions, and training of neural networks without relying on external libraries like PyTorch or NumPy. The library is designed to be readable for anyone familiar with programming, even without prior machine learning knowledge, and demonstrates how to build and train different neural network architectures using only C. It includes support for CUDA (tensor_cu.h) and example code for MNIST classification.
Key Features
Pure C implementation with no external dependencies
Tensor operations including matrix multiplication, ReLU, log-softmax
Autograd for automatic differentiation
Support for defining loss functions and optimizers
CUDA support via tensor_cu.h for GPU acceleration
Example code for training neural networks on MNIST
Educational focus: designed to be readable and help understand neural networks from scratch
Pros & Cons
Pros
- No external dependencies: only requires a C compiler
- Highly educational with clear, readable code
- Supports GPU acceleration with CUDA
- Lightweight and minimal, easy to inspect and modify
- Includes full example pipeline from tensor creation to training
Cons
- Not designed for production use; limited to educational purposes
- Limited documentation beyond the README and code comments
- Small community and minimal updates (single contributor)
- Lacks advanced features like convolutional layers or recurrent networks
Best For
Learning how neural networks work under the hoodTeaching machine learning concepts without heavy frameworksPrototyping small neural network experiments in CUnderstanding autograd and backpropagation implementationEducational projects and workshops on deep learning fundamentals
FAQ
What is tensor.h?
tensor.h is a tiny tensor library written in raw C, created to help people understand neural networks from absolute scratch without relying on libraries like PyTorch or NumPy.
Who is the target audience?
Anyone who knows programming, even if they are not familiar with machine learning or neural networks. The library is designed to be readable and educational.
Does tensor.h support GPU acceleration?
Yes, the repository includes tensor_cu.h which provides CUDA support for running operations on NVIDIA GPUs.
Is tensor.h suitable for production?
No, the library is intended for educational purposes to understand neural network internals, not for production deployment.