Aakaar
A high-performance, custom-built deep learning tensor library with a dynamic autograd engine and native C++/CUDA hardware acceleration.
Built from the ground up, Aakaar bridges the gap between Python's ease of use and C++'s execution speed, providing a PyTorch-like API for tensor manipulation, automatic differentiation, and neural network construction.
Official docs link:
https://aakaar.readthedocs.io/en/latest/
Core Architecture
Aakaar's Tensor is a custom C++ object that can live directly in GPU VRAM or in host memory, exposed to Python via pybind11. Tensors carry their own shape and strides, so operations like slicing, transposing, and reshaping return lightweight zero-copy views into the same underlying memory wherever possible — data only moves when you explicitly ask for it via .to_numpy() or .to(device).
Every differentiable operation records itself into a dynamic computation graph (grad_fn), which .backward() walks in reverse topological order to compute gradients — the same fundamental design as PyTorch's autograd, built independently from scratch.
Current capabilities
Tensors
- N-dimensional tensors on CPU or CUDA, with real shape/stride tracking
- Zero-copy views: slicing (
t[1:3, 2:4], negative indices, step slicing),.transpose(),.T(full axis reversal),.view()/.reshape() .contiguous()to materialize a view when an operation requires dense memoryfrom_numpy()to load real data in;.to_numpy()to get it back out.to(device)/.to_device()to move tensors between CPU and CUDA
Autograd
requires_grad,.grad,.backward()with correct gradient accumulation across branching (diamond) graphsretain_graphsupport for reusing a graph across multiple backward passesno_grad()context manager and.detach()for inference / parameter-update code that shouldn't be tracked- Broadcasting-aware gradients for every elementwise and matmul operation, verified against numerical (finite-difference) gradients, not just symbolic derivation
Operations
- Elementwise:
+,-,*,/(tensor-tensor and tensor-scalar, with full broadcasting), unary negation matmul()/@: N-dimensional, batched, with broadcasting batch dimensions on both forward and backward- Reductions:
sum(dim=...),sum()(full reduction),max(dim=...)(with correct argmax-routed gradients) - Activations:
relu,sigmoid,tanh,leaky_relu— all with float4-vectorized CUDA kernels and an alignment-safe scalar fallback exp(),log()softmax()(numerically stable, max-subtraction based) andcross_entropy_from_probs()
Neural network building blocks (aakaar.nn, aakaar.optim)
nn.Linear— a fully-connected layer with standard uniform initializationoptim.SGD— gradient descent optimizer using in-place parameter updates (copy_()) so parameter objects keep their identity across training stepszero_grad_all()for clearing gradients across a parameter list
Automatic CPU fallback
- If no CUDA toolkit is available at install time, Aakaar builds a CPU-only extension automatically.
device="cpu"works everywhere;device="cuda"raises a clear error on CPU-only builds instead of failing to install.
CUDA synchronization
Aakaar's CUDA operations execute asynchronously by default (matching PyTorch's
behavior). Call aakaar.synchronize() before timing GPU code or reading
wall-clock benchmarks, otherwise you'll only measure kernel-launch dispatch
time, not actual GPU execution time.
Tensor core acceleration (TF32)
On Ampere-generation GPUs and newer (RTX 30-series+, A100, H100, RTX 40/50-series),
aakaar.set_tf32(True) enables tensor-core-accelerated matmul via a reduced-precision
internal format (TF32). This trades a small amount of numerical precision for a
significant speedup — typically 3-5x for large matmuls. Off by default; tensors
remain float32 in memory regardless of this setting.
Installation
pip install aakaar
Prebuilt wheels are available for Windows (Python 3.10–3.14, with CUDA support). On other platforms, pip builds Aakaar from source — this requires a C++ compiler (e.g. g++) for CPU-only support, and additionally the NVIDIA CUDA Toolkit (nvcc) for GPU acceleration. If no CUDA toolkit is found at install time, Aakaar automatically builds a CPU-only extension.
Quick start: tensors and autograd
import aakaar
import numpy as np
# Load real data
x = aakaar.from_numpy(np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32), requires_grad=True)
# Standard ops, all differentiable
y = (x * 2 + 1).sum()
y.backward()
print(x.grad.to_numpy()) # [[2. 2.] [2. 2.]]
# Zero-copy slicing and views
big = aakaar.rand((10, 10), device="cpu")
view = big[1:5, 1:5]
print(view.is_contiguous()) # False — it's a strided view, no data copied
# Move to GPU
gpu_tensor = x.to("cuda")
Training a small neural network
import aakaar
from aakaar.nn import Linear
from aakaar.optim import SGD
import numpy as np
# Synthetic data: y = sin(x)
N = 64
x_np = np.linspace(-3, 3, N).reshape(N, 1).astype(np.float32)
y_np = np.sin(x_np).astype(np.float32)
x = aakaar.from_numpy(x_np)
y = aakaar.from_numpy(y_np)
fc1 = Linear(1, 16)
fc2 = Linear(16, 1)
def forward(x):
h = fc1(x).tanh()
return fc2(h)
def mse_loss(pred, target):
diff = pred - target
return (diff * diff).sum() / pred.size
params = fc1.parameters() + fc2.parameters()
opt = SGD(params, lr=0.05)
for epoch in range(300):
opt.zero_grad()
loss = mse_loss(forward(x), y)
loss.backward()
opt.step()
print(f"final loss: {loss.item():.6f}")
Notes and known limitations
matmulrequires contiguous tensors; call.contiguous()on sliced/transposed operands first.- Elementwise CUDA kernels also require contiguous inputs for their fast vectorized path.
matmulbackward supports broadcasting batch dimensions, but not yet arbitrary mixed-rank batch shapes beyond standard right-aligned broadcasting rules.- Only
float32is currently supported. Support for additional dtypes (float16, float64, int types) is a planned future addition, not yet implemented. - This is an actively developed project; APIs may change between minor versions.
☕ Support the Development
If Aakaar helped you learn how autograd architectures work under the hood, or if you want to support independent, dependency-free deep learning infrastructure, consider dropping a tip!
Metadata
Release files for aakaar 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aakaar-0.2.1.tar.gz | 12.6 MB | Without provenance | Details for aakaar-0.2.1.tar.gz |
Built distributions (wheels)
Total release size: 195.1 MB
Release files / aakaar-0.2.1.tar.gz
| Download URL | aakaar-0.2.1.tar.gz |
|---|---|
| Size | 12.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dae76df3e2f6eac5971608eb7e813b21e70b67ff4af1bbca2b81a712a2782dd2
|
|
BLAKE2b-256 checksum How to use checksums |
c4c9384f4df577b46833a0f08805aab997600db2327f5e40953d93472f8dbbcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp314-cp314-win_amd64.whl
| Download URL | aakaar-0.2.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 14.1 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
baba69415495a302e50414e321955f7e2c9e714ee5a64f70d1aff925969355ca
|
|
BLAKE2b-256 checksum How to use checksums |
9e0a59dfc5b63e91019e8197c07cdb4a77f50b02d6014714f4e16f5442dfa106
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp314-cp314-macosx_14_0_arm64.whl
| Download URL | aakaar-0.2.1-cp314-cp314-macosx_14_0_arm64.whl |
|---|---|
| Size | 22.6 MB |
| Tags | CPython 3.14 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dad4bad6231ed26af26a58f359cb817922674b0083efac5da0dcc6e412b91e49
|
|
BLAKE2b-256 checksum How to use checksums |
bfad747d582a36bc0429c1f821a3669c43f1af24910ad69077d9a5acd5edf189
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp313-cp313-win_amd64.whl
| Download URL | aakaar-0.2.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b5585dab408089d0671a026fc4a5f2f73ae827bbec85c90347419790c1225e10
|
|
BLAKE2b-256 checksum How to use checksums |
069316915af2f215647bd1be111983f35fdb06fefe8f68959305bf588735d0ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp313-cp313-macosx_14_0_arm64.whl
| Download URL | aakaar-0.2.1-cp313-cp313-macosx_14_0_arm64.whl |
|---|---|
| Size | 22.6 MB |
| Tags | CPython 3.13 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8a7a40322bef08efe9765179b0dd67b80e8d363a53823c75afb1fa9c3aea22ae
|
|
BLAKE2b-256 checksum How to use checksums |
883b04405380f2dd1918d384a21195c4af8877de3a5e61a1579adace928c5234
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp312-cp312-win_amd64.whl
| Download URL | aakaar-0.2.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4bcb15c121d8071201f4b6b6156d3b1a3fe59f9553b25cd62fb5bfaff9bd7e29
|
|
BLAKE2b-256 checksum How to use checksums |
4c566f021e27a299e9a4d2b84d9266321948a51b2298f88e03d6e5b0dddc3b70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | aakaar-0.2.1-cp312-cp312-macosx_14_0_arm64.whl |
|---|---|
| Size | 22.6 MB |
| Tags | CPython 3.12 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
47707b3e6aa4199694948cc4886dd1bc3cbd88bdd255f6c7f2a5659300f25815
|
|
BLAKE2b-256 checksum How to use checksums |
90ac150e76b4372f250bf09058243fdd445112e7c06837a93fefb89d5836edac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp311-cp311-win_amd64.whl
| Download URL | aakaar-0.2.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a935009f17d275a8ee7eea59705e891c528624a9ca200cc2034b70b5fc7a7a8c
|
|
BLAKE2b-256 checksum How to use checksums |
f605603ecf457593e8a1e2c4489a00b6ee8326184a246a996f97bf3a803702e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | aakaar-0.2.1-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 22.6 MB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ebed7c9c021b66b6819df95652bc220fc0f4e0d77614003bfde09c3551cd0045
|
|
BLAKE2b-256 checksum How to use checksums |
5e11a2ee0457ed6db97ad11b0b7e0054ef4ca9491d9081d1713169550aa78605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp310-cp310-win_amd64.whl
| Download URL | aakaar-0.2.1-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 13.9 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e2289b22d45601acda87102ff5a0419547b924263d46c58a4bf73da5f67e75db
|
|
BLAKE2b-256 checksum How to use checksums |
f7fce61f34a9e9b446aedba1c1ec4b7648140e1c352d3b48d543152055b64116
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / aakaar-0.2.1-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | aakaar-0.2.1-cp310-cp310-macosx_14_0_arm64.whl |
|---|---|
| Size | 22.6 MB |
| Tags | CPython 3.10 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e04d0eb737367da395c5398f969cdb8be2293cbebe66d7261fd0b886018dac54
|
|
BLAKE2b-256 checksum How to use checksums |
e9e2f2ab57b10489113055827a68d58f5c50dcdeed17b50f5bdc0fee79975e9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for aakaar 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.