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

Uploaded CPython 3.14Windows x86-64

aakaar-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.5 MB view details)

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

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

Uploaded CPython 3.14macOS 14.0+ ARM64

aakaar-0.2.0-cp313-cp313-win_amd64.whl (13.8 MB view details)

Uploaded CPython 3.13Windows x86-64

aakaar-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.5 MB view details)

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

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

Uploaded CPython 3.13macOS 14.0+ ARM64

aakaar-0.2.0-cp312-cp312-win_amd64.whl (13.8 MB view details)

Uploaded CPython 3.12Windows x86-64

aakaar-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.5 MB view details)

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

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

Uploaded CPython 3.12macOS 14.0+ ARM64

aakaar-0.2.0-cp311-cp311-win_amd64.whl (13.8 MB view details)

Uploaded CPython 3.11Windows x86-64

aakaar-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.4 MB view details)

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

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

Uploaded CPython 3.11macOS 14.0+ ARM64

aakaar-0.2.0-cp310-cp310-win_amd64.whl (13.8 MB view details)

Uploaded CPython 3.10Windows x86-64

aakaar-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (31.4 MB view details)

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

aakaar-0.2.0-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.0.tar.gz.

File metadata

  • Download URL: aakaar-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fb9e5aa0272ef9f6b49f4d3fc244d96603a6b920db7a27781988b575ad49a3cb
MD5 648221377a2b7ff44ee6a02366dff2fd
BLAKE2b-256 94308a2abb4aadfd3586604f55d45349d741e306b5823efcd2867d9161156f05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 14.0 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.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b081aaf7be22e9b07db27f877b6f5875c84db1f9946dd2d20648a27092813792
MD5 3f67c449622715f8d6b4068feb3c3b6b
BLAKE2b-256 012225ed952858beadcadd8c64c20758f790892f1282059d7b9edc33048befe4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9b60a5b3de79d7b2ebbe87ae30122a213f980438c518fba49f23ac8b17ae141b
MD5 966224b2238513162112dd7fb2556630
BLAKE2b-256 554f3356f49493bd18878b1cd78980360fde46ae7abed125e3bd6b1f1da78cc7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 99a54699a86d7fa1dd97e36b84b46aaa3166b92076597b33402a32dc86700acc
MD5 df541f5ca2f99f942f2d0248165b362f
BLAKE2b-256 780b560c864087405e4387e19699a55c5d65085448dd2317c9d761984b7cc086

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 13.8 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 630d186572cc938bff86de4a3a0368551a1073ddcf35ad9dd7cb6c9e40151f72
MD5 e29cd35c18b153aa6a2d174f2fc434b8
BLAKE2b-256 1a541731b84330958a297edf012bc8d09d12ec57e2ce065c0da07a2d8aa67b97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca9a0f8acb8a02e360868ca7974dea12482ebbee817f7a0c29e7ecef9728af58
MD5 0a1cbc3ca5529f2db86c45fab48ebc61
BLAKE2b-256 0a589f7c4336f01c44be566c97da6e80eb9b0e3ccd0b47fe940eea4f09bc6d64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 42d62a2d0c54632bd55fa87c39b7817b9d3e0961e3f74fbfd969a8e85cde8ac7
MD5 7d1f9cd04a80f694ee29e0df9013d939
BLAKE2b-256 21231e566ed3a2aadad7804adb6490195c9b574b6fb4e794a3fc9a01730966ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 13.8 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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8d9a416222d416f308ad169fb72c653192617b29aeffa28fb3e841e891e8e6fb
MD5 638589b76768a127dcd09cd206ac9700
BLAKE2b-256 cf23b26aed9029c88d575c8a438c91985392e35875b9d0caa9f0286e7ddfb501

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a9cc9a1b3b1853244b745b5cd4c0adfaf0ab8ccd783c231cf8f0414c54e647e
MD5 9ca0a075ab8849d8e57947b13c7fe5cb
BLAKE2b-256 afa33afb00505a52cba8ebfe23be7d255f6b000821853d327a6b2d2acc78e833

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b6a7105c6cbf257b4532067653f561fedb22235a634fc8966517ca18d3828ee2
MD5 93dba37b8f365324bd43cb61b4879f2b
BLAKE2b-256 ba1a28469343f24ef802ee7b674600bb218c94479deabe70e0373cb1cc9dce0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 13.8 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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1868941511181843f452d3570a5611b2c263f8efe5434f8a2da35cbd89b298d3
MD5 5a11012343dea52b2b07c10b620373eb
BLAKE2b-256 126ad81252fe375908b2a01cb602094250e7d9db98f937b3a904d128d5b50cd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 515a09867451b02eb1727e5dbdd15737053dda0bb8a106f9877ecc246606c896
MD5 8621960ff171dd00fb8659a432b04a14
BLAKE2b-256 c994336232e90baec6c2775f50ed0580ed398c2db43b3147790f81d736dd8e8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c9d942622cbc850e0c69e4f4cf83c590496b80d9141219ebc5480d153f31a2dd
MD5 fc187dfe581195b4dca66adec7a0b8d3
BLAKE2b-256 043a4a1a562e67f4bfb577d0f22bf1c1113944a0f214b6229f557f83d830fc3f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 13.8 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7ff3900e0b265182f089f97883577dc1966f42e08178f795eaf49e17ed088200
MD5 5381df7a1fb4d2e4e59cbc7188e5749f
BLAKE2b-256 2fb779ea496c1a67f8534aafd26b665a9c9efb1ff8fa12cac7f30a046bda0475

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 11d2b0f7e165c4eb23eb6cff7c8ad9caea746415d85744bfe759f84d4b0043a7
MD5 738bef600f280ef2feea78e5f9624ff3
BLAKE2b-256 7220633bd3dbc67abc0309b6064654d654658a0a40abbe488cb218d501a2c0cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.2.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e5d1fffd9da259272895951bbcc5e437be87597e71ab615e40c3f68e41c1187e
MD5 b7e229df23ae861c96ee29302ce72425
BLAKE2b-256 9c2e5150dedf3ae83beebcf0fdbe076dd68394633e960087bb0a1f54e9444ffa

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