ClumsyGrad
A minimal Python library for automatic differentiation, built on top of NumPy. The Tensor class has support for creating and expanding a computation graph dynamically with each operation.
Features
- Dynamic Computational Graphs: Graphs are created on the fly.
- Automatic Differentiation: Compute gradients automatically using the chain rule.
- Basic Tensor Operations: Supports addition, subtraction, multiplication, matrix multiplication, power, exp, indexing/slicing, etc.
- Gradient Checking: Verify backward-pass correctness against numerical gradients.
no_grad()Context Manager: Disable graph tracking for inference or manual updates.
Installation
You can install the library using pip:
pip install clumsygrad
Basics
Here's a brief overview of how to use the library:
Creating Tensors
from clumsygrad.tensor import Tensor, TensorType
# Create a tensor from a list (defaults to TensorType.INPUT)
a = Tensor([1.0, 2.0, 3.0])
print(a)
# Output: Tensor(id=0, shape=(3,), tensor_type=INPUT, grad_fn=None, requires_grad=False)
# Create a tensor that requires gradients (e.g., a parameter)
b = Tensor([[4.0], [5.0], [6.0]], tensor_type=TensorType.PARAMETER)
print(b)
# Output: Tensor(id=1, shape=(3, 1), tensor_type=PARAMETER, grad_fn=None, requires_grad=True)
Performing Operations
from clumsygrad.tensor import Tensor, TensorType
from clumsygrad.math import exp, sin
x = Tensor([1.0, 2.0, 3.0])
y = exp(x**2 + 3 * x + 2)
z = sin(y)
# As implicitly tensors are of type INPUT, the computational graph is not built, signified by
# grad_fn = None.
print(z)
# Tensor(id=6, shape=(3,), tensor_type=INPUT, grad_fn=None, requires_grad=False)
print(z.data)
# [0.9648606 0.99041617 0.83529955]
x = Tensor([1.0, 2.0, 3.0], tensor_type=TensorType.PARAMETER)
y = exp(x**2 + 3 * x + 2)
z = sin(y)
# Now, the tensor is of type PARAMETER, and the computational graph is built.
print(z)
# Tensor(id=13, shape=(3,), tensor_type=INTERMEDIATE, grad_fn=sin_backward, requires_grad=True)
print(z.data)
# [0.9648606 0.99041617 0.83529955]
Automatic Differentiation (Backpropagation)
Consider the function $~z = e^{sin(x)^2 + cos(y)}$. We can evaluate $\frac{dz}{dx}$ and $\frac{dz}{dy}$ at particular point as:
from clumsygrad.tensor import Tensor, TensorType
from clumsygrad.math import exp, sin, cos, sum
# Set tensor_type to PARAMETER to ensure gradients are tracked
x = Tensor(1.0, tensor_type=TensorType.PARAMETER)
y = Tensor(0.5, tensor_type=TensorType.PARAMETER)
z = exp(sin(x) ** 2 + cos(y))
# Calculating dz/dx and dz/dy
z.backward()
# Value of dz/dx
print(x.grad) # [4.43963]
# Value of dz/dy
print(y.grad) # [-2.34079]
License
This project is licensed under the MIT License.
Documentation
For more detailed information, tutorials, runnable examples, and API reference, you can check out the official documentation.
Metadata
Release files for clumsygrad 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| clumsygrad-1.0.0.tar.gz | 25.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| clumsygrad-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.8 kB
Release files / clumsygrad-1.0.0.tar.gz
| Download URL | clumsygrad-1.0.0.tar.gz |
|---|---|
| Size | 25.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f18f1e7bdd688bcb2b941b0860450ffeaa24aa237d051e4e705fdee1838b31b
|
|
BLAKE2b-256 checksum How to use checksums |
c6930f4a068084b1669656b3b421d318e06e23edf4abae086a44e805de313945
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.
Transparency logRelease files / clumsygrad-1.0.0-py3-none-any.whl
| Download URL | clumsygrad-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f4413de57ef684d511c2b69d9ec0d15836948bdbc45fff11aa94e3d2f998eea
|
|
BLAKE2b-256 checksum How to use checksums |
fd4e6f11c2076952066e61604a099cb00ac87ac00479a38ee8f2092a28a74cd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.
Transparency log