Skip to main content

Aakaar Logo 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 memory
  • from_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) graphs
  • retain_graph support for reusing a graph across multiple backward passes
  • no_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) and cross_entropy_from_probs()

Neural network building blocks (aakaar.nn, aakaar.optim)

  • nn.Linear — a fully-connected layer with standard uniform initialization
  • optim.SGD — gradient descent optimizer using in-place parameter updates (copy_()) so parameter objects keep their identity across training steps
  • zero_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.

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

  • matmul requires contiguous tensors; call .contiguous() on sliced/transposed operands first.
  • Elementwise CUDA kernels also require contiguous inputs for their fast vectorized path.
  • matmul backward supports broadcasting batch dimensions, but not yet arbitrary mixed-rank batch shapes beyond standard right-aligned broadcasting rules.
  • Only float32 is 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!

  • International Supporters: You can buy me a coffee via Ko-fi (Coming Soon) using any standard international debit/credit card.
  • India (UPI): Since international gateways occasionally restrict domestic transfers, you can support directly via UPI:
    aaravaggarwal3535@okicici

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aakaar-0.1.11.tar.gz (12.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aakaar-0.1.11-cp314-cp314-win_amd64.whl (13.2 MB view details)

Uploaded CPython 3.14Windows x86-64

aakaar-0.1.11-cp314-cp314-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

aakaar-0.1.11-cp313-cp313-win_amd64.whl (13.0 MB view details)

Uploaded CPython 3.13Windows x86-64

aakaar-0.1.11-cp313-cp313-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

aakaar-0.1.11-cp312-cp312-win_amd64.whl (13.0 MB view details)

Uploaded CPython 3.12Windows x86-64

aakaar-0.1.11-cp312-cp312-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

aakaar-0.1.11-cp311-cp311-win_amd64.whl (12.9 MB view details)

Uploaded CPython 3.11Windows x86-64

aakaar-0.1.11-cp311-cp311-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

aakaar-0.1.11-cp310-cp310-win_amd64.whl (12.9 MB view details)

Uploaded CPython 3.10Windows x86-64

aakaar-0.1.11-cp310-cp310-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file aakaar-0.1.11.tar.gz.

File metadata

  • Download URL: aakaar-0.1.11.tar.gz
  • Upload date:
  • Size: 12.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11.tar.gz
Algorithm Hash digest
SHA256 b90932aeb80a449cc60009a64344473cc943f834df76d2c36e6321269eff381e
MD5 f43589922ce4e6e0db712677c94d9464
BLAKE2b-256 5b7682c8f822c2b74edc078a89321a6d1d9b04263c44e692b744d770859f68bc

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.11-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 13.2 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1f69e49bf79607e038913cd8a1a13f5fa1f48e4565b1f51e6020fc1051b6d521
MD5 0a3c3e73aa8155f248f25a95797d9b84
BLAKE2b-256 0424eedf7f071fc57a331de220fef5d0ad1d5dd0550789dc4e3cb05504d253d4

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.11-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 639986180ce541b5b457d3a2de9a8f0c4a0065a64b05a0536a4d167932adf512
MD5 8d1e2001b7ca624294bf12a78c9c84c1
BLAKE2b-256 9c854f374a38d9ae7e4ac18453a37868d035beaba6b9a6fc1e56a27da7c29654

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.11-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 13.0 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9b5836e972dada92325ff0589d6ca3171aa7f26b188fdf72831164ec305b8375
MD5 4a3f12a74b5aa76bb35554da8312d27a
BLAKE2b-256 da3c93857744de4697f45b1fb98ef79f2c5731d7550230f899f8de2c30a72955

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.11-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a6747e9b91878410a10d8f06866fa1e2d53194bd07f8e80dd6ccaa7eb6f8b485
MD5 fceeea35a6b6af0f2475cfd87916fcdc
BLAKE2b-256 8bceba142a6a4ac221d612f3d6abaa61627061b1937b43b2f537380b283b7e2c

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 13.0 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bf47e6fad4698e4ed49867be42eb05d01f4f9119618adb07f1f4536da4856111
MD5 0e717154db8333e324cd6007f87a4aee
BLAKE2b-256 6b31427267c70126eb8d2b33b08bd94219519790ba22ef33b51f800ca53f9d05

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.11-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7ad3a82fe31e98af415cbfd3cb4cb7370ad78364c429c9be5466ee97bd042b0e
MD5 5bc6d99db48e5ee7d6edf69c5682869a
BLAKE2b-256 0a86bacb4f48f1fc3e0d9d43cdf11a64d928e4ae36315634d3cc37eaf420be87

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.11-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 12.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0891842bb7978289c27048ada6418479a8a8fe15d675aa1048e67b7962ed88a1
MD5 98461687f9f9bba5825c78b96b79909c
BLAKE2b-256 5d6fd97df9adacd0b89f6f8ec3468a175fc5fd4faf3bfdda58236d0a2c3eaf17

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.11-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0eb65c04ece56395c4381bef46bd9f54ebf1b1e592ba97367f800a263eda912d
MD5 5e846c2dbee1a94059a1e9e38f32bdbf
BLAKE2b-256 dd8e3bb60afcb98badb36f8c153adacdfe191ac467f77fd4610fa0c1d55f5c64

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.11-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 12.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for aakaar-0.1.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 49bcb95fb77a9f88dd4787364cf63814d707b27b6b9eda931458e4c9852f0f98
MD5 1c2daae99c61ffdb4cf35bee11651ea2
BLAKE2b-256 cda2bd290337addf69dde7594446a3a892aead2ac8b22ed6b4ef504195b3c1e7

See more details on using hashes here.

File details

Details for the file aakaar-0.1.11-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.11-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0d9e3e0ad3a545246e8c3f5c9c86f2280eb90d551bc06b9fb170a8c9cd81f186
MD5 7e13025c87350ad45d576bea97458b81
BLAKE2b-256 3046fc31d4b70ad53ad3e47f17d5763c09f1a572425e4f14932d5f7cd652ad99

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page