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.

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

  • 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!

Sponsor Aarav

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.2.1.tar.gz (12.6 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.2.1-cp314-cp314-win_amd64.whl (14.1 MB view details)

Uploaded CPython 3.14Windows x86-64

aakaar-0.2.1-cp314-cp314-macosx_14_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

aakaar-0.2.1-cp313-cp313-win_amd64.whl (13.9 MB view details)

Uploaded CPython 3.13Windows x86-64

aakaar-0.2.1-cp313-cp313-macosx_14_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

aakaar-0.2.1-cp312-cp312-win_amd64.whl (13.9 MB view details)

Uploaded CPython 3.12Windows x86-64

aakaar-0.2.1-cp312-cp312-macosx_14_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

aakaar-0.2.1-cp311-cp311-win_amd64.whl (13.9 MB view details)

Uploaded CPython 3.11Windows x86-64

aakaar-0.2.1-cp311-cp311-macosx_14_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

aakaar-0.2.1-cp310-cp310-win_amd64.whl (13.9 MB view details)

Uploaded CPython 3.10Windows x86-64

aakaar-0.2.1-cp310-cp310-macosx_14_0_arm64.whl (22.6 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for aakaar-0.2.1.tar.gz
Algorithm Hash digest
SHA256 dae76df3e2f6eac5971608eb7e813b21e70b67ff4af1bbca2b81a712a2782dd2
MD5 91dd5086348d5ecddbe391b28863f6b3
BLAKE2b-256 c4c9384f4df577b46833a0f08805aab997600db2327f5e40953d93472f8dbbcc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 14.1 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.2.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 baba69415495a302e50414e321955f7e2c9e714ee5a64f70d1aff925969355ca
MD5 b6c494714605593c462fca7a22a3de1c
BLAKE2b-256 9e0a59dfc5b63e91019e8197c07cdb4a77f50b02d6014714f4e16f5442dfa106

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.1-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dad4bad6231ed26af26a58f359cb817922674b0083efac5da0dcc6e412b91e49
MD5 2dee8c1dc34b2a6464f21823adfc912d
BLAKE2b-256 bfad747d582a36bc0429c1f821a3669c43f1af24910ad69077d9a5acd5edf189

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 13.9 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.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b5585dab408089d0671a026fc4a5f2f73ae827bbec85c90347419790c1225e10
MD5 f4aa3311b2dfb87b184996657ff4e6f4
BLAKE2b-256 069316915af2f215647bd1be111983f35fdb06fefe8f68959305bf588735d0ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8a7a40322bef08efe9765179b0dd67b80e8d363a53823c75afb1fa9c3aea22ae
MD5 a69d9217b78e5da3be23d5ab0271a42d
BLAKE2b-256 883b04405380f2dd1918d384a21195c4af8877de3a5e61a1579adace928c5234

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 13.9 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.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4bcb15c121d8071201f4b6b6156d3b1a3fe59f9553b25cd62fb5bfaff9bd7e29
MD5 97057fdb1c0c7881f0e284fe8a46361d
BLAKE2b-256 4c566f021e27a299e9a4d2b84d9266321948a51b2298f88e03d6e5b0dddc3b70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 47707b3e6aa4199694948cc4886dd1bc3cbd88bdd255f6c7f2a5659300f25815
MD5 08e967d07cc9fa50c2356c8d56f10949
BLAKE2b-256 90ac150e76b4372f250bf09058243fdd445112e7c06837a93fefb89d5836edac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 13.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.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a935009f17d275a8ee7eea59705e891c528624a9ca200cc2034b70b5fc7a7a8c
MD5 53d1fe2926ff422384a3017770581eeb
BLAKE2b-256 f605603ecf457593e8a1e2c4489a00b6ee8326184a246a996f97bf3a803702e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ebed7c9c021b66b6819df95652bc220fc0f4e0d77614003bfde09c3551cd0045
MD5 00a7693aad7d6f01423b5e6241134a9c
BLAKE2b-256 5e11a2ee0457ed6db97ad11b0b7e0054ef4ca9491d9081d1713169550aa78605

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 13.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.2.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e2289b22d45601acda87102ff5a0419547b924263d46c58a4bf73da5f67e75db
MD5 9934bf4111036de3d585fdc080a57184
BLAKE2b-256 f7fce61f34a9e9b446aedba1c1ec4b7648140e1c352d3b48d543152055b64116

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e04d0eb737367da395c5398f969cdb8be2293cbebe66d7261fd0b886018dac54
MD5 0d963c88a0e3dcafd23dd72d7c2af9ea
BLAKE2b-256 e9e2f2ab57b10489113055827a68d58f5c50dcdeed17b50f5bdc0fee79975e9b

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