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.12.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.12-cp314-cp314-win_amd64.whl (13.3 MB view details)

Uploaded CPython 3.14Windows x86-64

aakaar-0.1.12-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

aakaar-0.1.12-cp313-cp313-win_amd64.whl (13.1 MB view details)

Uploaded CPython 3.13Windows x86-64

aakaar-0.1.12-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

aakaar-0.1.12-cp312-cp312-win_amd64.whl (13.1 MB view details)

Uploaded CPython 3.12Windows x86-64

aakaar-0.1.12-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

aakaar-0.1.12-cp311-cp311-win_amd64.whl (13.1 MB view details)

Uploaded CPython 3.11Windows x86-64

aakaar-0.1.12-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

aakaar-0.1.12-cp310-cp310-win_amd64.whl (13.1 MB view details)

Uploaded CPython 3.10Windows x86-64

aakaar-0.1.12-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (28.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

aakaar-0.1.12-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.12.tar.gz.

File metadata

  • Download URL: aakaar-0.1.12.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.12.tar.gz
Algorithm Hash digest
SHA256 0cf90f651108bc780b0ce9e6febf8df6d445604ed22af8d6849e8e55089522d5
MD5 653a4bc81da4f3cd2cc775cab2c2f97b
BLAKE2b-256 d19978af4e9000b9a35624d4dfde0a26db2f39846d9ca6958df1587f2bf5da5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.12-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 13.3 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.12-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 c609e3e7dc7067b91c95fd135a23db91a62ed82dc300017652484a873c37f514
MD5 5e9e6ac18656ae068302910ae3890b1c
BLAKE2b-256 3875527c73f97c6b492735ad2be4fe77b523865d4607a940d3f1d64591ac7027

See more details on using hashes here.

File details

Details for the file aakaar-0.1.12-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.12-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 262881d7026573647a9b151388c8bb3e16d57a6eaea12caf83967d5120426129
MD5 b36df0354015af4cc48cad523665f8f1
BLAKE2b-256 bba58ba21cc500d1d35e2eca8423e52150c8ece1855dc1d8c300272d184827e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.12-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d5bb7bf8332a48c45d894a88d146c4e7df3ad002015a51faf2f0d430f364d1c4
MD5 16f9b0a65255c9d28c386362b5e6d79f
BLAKE2b-256 f4b076765ff51e63521a51607699c8cb84829b2745d63c76d012be571046f96b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.12-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 13.1 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.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8a0a84020491c71eaf3f53da27c51bbf883a571df652ad2860b7a516263bf623
MD5 a48f2ebe40068262122ed584d5621a96
BLAKE2b-256 1b46462801a1820da77e25939fc71500e61a9362a72a27ed78fac8c1eae49886

See more details on using hashes here.

File details

Details for the file aakaar-0.1.12-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.12-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bc44bebec15fac8e45d1066c41bb2a86180a4cf1132fb5f88e5c3eed2370e3dc
MD5 ee0ea9fbb71ec71b64d6e5a256133950
BLAKE2b-256 de082d691c41e24f90737ed37300b48e14eeba3dca4d993f00eb3f34a9fa97bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.12-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 21e4595565caf97849011a76021439704939c6a1173dcccb901c86bf2c388a8e
MD5 8bc9dfecd30eddd88b580ef9cb8eefdb
BLAKE2b-256 28abceb438cfd2dafc540f0511db6776474f117b33a0562a0d3c9a1acb1e9f10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.12-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 13.1 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.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 05d7fc71f4aacd59db3f0901208c09f83f401bf68ddd60e56cc388a74b4643c5
MD5 e0fdbe37c3205fef80ea61276e42e3b6
BLAKE2b-256 affffb3cd1ed68de934c52131f57d26e4f82a6dc157916454857eb9d04508940

See more details on using hashes here.

File details

Details for the file aakaar-0.1.12-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.12-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 782af068f6d6b3e6349d5964a1b553062b37145f9a9b0e82c8679369fd0b3d8e
MD5 eac8d95c082a73788700f42b36311edf
BLAKE2b-256 f87413825254d7ceb85866cd1bd587bc9cfb723589560dcea95f72933e9f6844

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.12-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8b47f3292043486ada7487facc03146dff367a96169e89eaed38120be50270db
MD5 773e3489a16934856e9123c51216967b
BLAKE2b-256 0a69f8276fc2421a2a9ea1a08fa81203c49936a03178f562c5f8fa05c8a6927c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.12-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 13.1 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.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9c138b261971705248b94499c2e6a5f2bb71a9c4f168de835e13398943834a83
MD5 5a9385ffc91ce23d9f54b75b6f834bf6
BLAKE2b-256 9cd81600d8f85b6f690108595e217505fa7b47639afd00ffac7a26b6a5e955a9

See more details on using hashes here.

File details

Details for the file aakaar-0.1.12-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.12-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75edfff8abf8652bb42bf44f13339eefd75df25b7cccaa618540a60e26146f53
MD5 8d8d2d30cea3a1a7b3a50c97db7d1808
BLAKE2b-256 94518478f05dda73e9c1b58f2cea0d8c1fe6ce07b12ba092f7aadef0acd16aff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.12-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d16063b6608436164e918ab21e97cedf45a84ae4130130d8acda86e2d93c36a5
MD5 3cf84d815d29eb1e973e1bec0f5954f5
BLAKE2b-256 858ee4d172c3469583596603122085abfda9a6928d19be842c2afc76c3f0fc27

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.12-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 13.1 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.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ec905d3e687a282ba9c16b818f75efa170681f2c43be5e3143963b34bacfc439
MD5 0ec615210d7750083f1fe3a0f9ef12ed
BLAKE2b-256 acf293ec1f0ad647fb2c96ea35aa25991320e00228cfdc85d56c2747016c6a03

See more details on using hashes here.

File details

Details for the file aakaar-0.1.12-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for aakaar-0.1.12-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 692131a1a14c3baa1d86aecacfeef91d78be92fb6807a81738c80b7bfe5d7c00
MD5 83cdf27bbd50de42cb09ecc0196deacf
BLAKE2b-256 58de8b47fa0563c03b8fb144e084a543b1fae18093e3613ac8ca700e99c988cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.12-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e8f0afc1d38d08f10cffa7bbe0da4c2292bcd8029434d09ae402baa3e0334e1d
MD5 6b616e663ef4e77367e8725ad008fa96
BLAKE2b-256 4768272136abc108d986f7b72822549dc266cdfd331d850d2d7ba52a631c377b

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