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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

aakaar-0.1.14-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.14.tar.gz.

File metadata

  • Download URL: aakaar-0.1.14.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.14.tar.gz
Algorithm Hash digest
SHA256 aa221913f824c77be9cbd343bcc1f9e6c7fcc4a9db1faf5fd2c95bf186f0301d
MD5 5c3641d955aa038ebea8639cacb0eb66
BLAKE2b-256 628a53275973a890425eeb63f6eb868cde8d71adb773c32525a950895758c96f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.14-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.14-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ab7a5b7a99e635c2918c414188e772bdff106a029ee3a3de6e74eaab605a7dee
MD5 2148aa7471d5e95b9c09e1d5f7584360
BLAKE2b-256 e8a6233d9d987ceca0d9b2e0e18099b2583ea96c0d69501122265d68da725326

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.14-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d0b92a7ffa9ac5917ca0511d98e6920e7cb1057faf4f9571b54e8bed527fde84
MD5 8b8eb3cca39c0d2dac708d848a15009d
BLAKE2b-256 e134acdad4e96294e6d7cf11fa1f93e52ca1ea9fa3879801ad5b3bb6df2e7ddf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.14-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.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c7b35fa5cb51605fcba7e20c8d77e9ec3ad286e24c6dd286e21dc859fcda2db8
MD5 ef627fbd58fc0f2cea833a893d05a037
BLAKE2b-256 6ae91b88b13089620bc8a9d106f8ce2117e4a0965321155581db61d176f8396d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.14-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 88a67694589f87ecff2b5b5384e8856d7cfd37bdcdf89efae5ef7ad05751caa1
MD5 c28820bda620e651e27d683f34a36841
BLAKE2b-256 e4a9ff5db3cf20056b6be2a69a2aff5ffc7204c0bd981831aa81096982f51fc2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.14-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.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 33d0439a8ec14634b372f10ccce4b137907c44a2900d5da12e527022e1707dc0
MD5 9dad6effb202bd21d6906de63f2eacbe
BLAKE2b-256 a3301b19323f1c599f27cea882525d991ce969eaf8de197ed63636c59a8b93f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.14-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1a0b642d315f44b97b633d490f15161c2645127ffe3407e87812c91c8c1f2a0a
MD5 ced3edd6e9caf0f8bca032b6ff6d358e
BLAKE2b-256 e4254fb4ca66caff476fd3f192e30e5942bfb286b13013312aea0b1ce6226801

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.14-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.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5fad14022841ec770c4b77e37a8e6bdbbe8e0340f87d851bf13a3ebbd9a0c59b
MD5 6f80b797fb31b63c50df334cb7b17aea
BLAKE2b-256 ebc2d9eda762cfb24a2bee75625a480a7d58adc9f5955cb14659ea16f93857f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.14-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 611a01e1381e0826a5be0c2a8487b7205be352ca72d6958782c0a8608d9efa2d
MD5 bdca70dead1ea85aa494c43a3ce1fb28
BLAKE2b-256 1c17fea707629bf60f6d41b6448374ed4914d444aca6a0558ce198346b2fba4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aakaar-0.1.14-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.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a7e8df95c5e6f618288fd046ee84996c2d2865601e3ba3e3d3017d6b3f01e75c
MD5 18cdb2ba0d810eba6a196fb50db079c7
BLAKE2b-256 44ae9d9bce935729a5778da4e444ec4a768ca88850b0501d7b857ead16a1277a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aakaar-0.1.14-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ac358133f256030c4e8a0d09c202c06a27e3e1eaa4917621924ae65a8c5078e2
MD5 57b03fd5b3607a2bff57a218bd4385c2
BLAKE2b-256 55564ce09e8166231b9d3362001481bb496e7e266898e8730f3e3a05c3cd5785

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