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

Uploaded CPython 3.14Windows x86-64

aakaar-0.1.13-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.13-cp314-cp314-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

aakaar-0.1.13-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.13-cp313-cp313-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

aakaar-0.1.13-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.13-cp312-cp312-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

aakaar-0.1.13-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.13-cp311-cp311-macosx_14_0_arm64.whl (22.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

aakaar-0.1.13-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.13-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.13.tar.gz.

File metadata

  • Download URL: aakaar-0.1.13.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.13.tar.gz
Algorithm Hash digest
SHA256 6d32a94b64ac630cd85af1ac354edc1ea677244fe537a98767940640b352ced3
MD5 6b012778b2814de917b63ecc3ed579a4
BLAKE2b-256 b3ceb5e054f4af12420df21038b7e24fce61aa4c39c0f245bbb0d1bbebc73484

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.13-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.13-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 a7dd3c2adb8ec8fabd7082f07dce39653f71e59c7e7d68ab032ea2c4c95284a9
MD5 12b29e5e62e06c5a61843e56247e2fb0
BLAKE2b-256 5857d918b7d5b08fce6efeac2fad7f7050a03cb968db8ebd9a2c27f9b50c90b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a31759d284cfc722daffa01b2dd61ec6c0c0956894f67439b9185003841bdb0
MD5 47e1a6b47b451c18d473bd0991f3bba6
BLAKE2b-256 a59b3bb6422ed78f48fe44c07da11a50562e104c31a09a7e85af48de1d3e98b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3926e00c13601d6b64c3a5e5d3df241903d6da1d183a73f675afe9fd997a6b4f
MD5 44992d0597687154ee8a0493ea692197
BLAKE2b-256 c9750fbd2b6b78fc54f9f4edc254bf3b7fa477c52d88797c56bf49a3b8afd225

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.13-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.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b3f377821649bdb2a74861dae32a419ce9a5b799ca64f0e9e09e40b4692ce492
MD5 8cd15aa29e433ec18a9859bb1bdc34f1
BLAKE2b-256 dd552371a354506ef5812377f0c9219be828f296909902e5842a518be41e9198

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb984d149bdef258135094856c465da028d37ffab6ff07aefddfa33438e99bd1
MD5 954cf063ab76452a458bffc8676d2273
BLAKE2b-256 a360c1fa24c8a63338eb38002df63061446332beb1926e881dff120d441dea71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4135de03b0f5622073fd7eb51c4561737a2e450b94e52186bceb06f8e5b75962
MD5 e633f7a61456e4fa4f9d46edf6738d50
BLAKE2b-256 5efa6696df12196a950a1ba02559cd399fc7102035abdb71affc3dd55ee8d005

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.13-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.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 581329bb9268b4eaf3896149e86c7939c18b82ee323f5c1024c8187d023329e7
MD5 2adecb7fd06f8fcb708dca640b50ca7a
BLAKE2b-256 9c0e6f1c0dcb3b2e7abd0dfcd1eaaa5a74b5eda67945e7897bfb310704155d5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a8ff7df2e4f8c350ea01cc2f16470ade9006317d40b7e529c668e19518375973
MD5 538c178444f1fd685c9d751ac548e353
BLAKE2b-256 7fcfa4745d9263d050f869590c2a498ca41b87b9d623ce25084227737504bbc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7cc20e4a44a2fb2fbebdb6115fb5c76bd88fddb19750026fc3c2d37d51ce9b9f
MD5 b00a4aec98964f2bc3f83302994cba2d
BLAKE2b-256 d84f71a171927bce92dda0b08c61b4d53dca9f3c2d92d1ea5a78a041b4cb3d4b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.13-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.13-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b1e49debb78e546e6185e92ed70df8c4c78dd424f7a8cf4b9008b4f7b2ac3f29
MD5 b6597eb2713a0d63edaf26112c42708a
BLAKE2b-256 9f3dfa505fb523bdab7ad55bd28452f2482b97876561636222694b987455d643

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65705786c741da596b67299a820827c0d153aece7971baec5c0f912c7b8bfcfb
MD5 2a2aaec392945f5de0b6a8ffdae0e759
BLAKE2b-256 fd4ed826c3aa1307a8e20abd07e24b3add8aefd00a48a0e46dfa5cadae0da4a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 20561776863ceca40b7897a4a45fe83c2da85e56c872316fc419423967c0e463
MD5 f16b8e4aca79b272de2cb47227e15895
BLAKE2b-256 20de4f90735d9c6c4dd49569952ec92038b96d27925da81021507c0ad19d61a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.13-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.13-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 205e32442a4e106b7309e1379e02f455d597b932fb8ca8da2fcb77304dab9cfa
MD5 a90ab2996fccb39e2c5294949b719d34
BLAKE2b-256 e5c82cce10f7454b240ac5b0da55f14f1266c297c756ea3cbb9090842b4cc830

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 33e8918a841aafa93fcc20dea81e025899e2cbbfd469fb6d9cf2f5ef5914846e
MD5 222ff5451a2db6ceae69fe3320d82430
BLAKE2b-256 86a5b8630989228f9fbfda160e8aa601b8b8aa72c095307428c4570c8e8fac70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.13-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5d2a78a96b706187d72381967b7b25a797d1a5b4391d58cf3fc0503af98909de
MD5 406a66eccf253777ea2cf92379e0be81
BLAKE2b-256 2b6e96287e93b01344f9313792083410851b596f1c63ab7c8e011f8da21cf2c0

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