Skip to main content

AffineFlow

PyPI version Python

AffineFlow is a unified, high-performance Machine Learning framework tailored for speed and mathematical transparency.

Under the hood, AffineFlow acts as a pure Python API routing to highly optimized, custom-built C++ native engines (affineflow-ml and affineflow-nn). By pushing computational bottlenecks—including the entire training loop—down into C++ via pybind11 and Eigen, AffineFlow entirely bypasses the Python Global Interpreter Lock (GIL), resulting in execution speeds up to 100x faster than traditional Python-based ML libraries.

Installation

Install the complete suite via PyPI:

pip install affineflow

Modules Overview

Once installed, use the unified affineflow namespace to access both classical and neural sub-modules.

1. affineflow.ml

Powered by affineflow-ml. Features a highly optimized K-Nearest Neighbors classifier and Principal Component Analysis (PCA) adhering strictly to Scikit-Learn API standards.

import numpy as np
import affineflow as af

X_train = np.random.rand(100, 64)
y_train = ["A" if i % 2 == 0 else "B" for i in range(100)]

# Initialize and fit model using Scikit-Learn standards
knn = af.ml.KNeighborsClassifier(n_neighbors=3)
knn.fit(X_train, y_train)

predictions = knn.predict(X_train[:5])
print("KNN Predictions:", predictions)

2. affineflow.nn

Powered by affineflow-nn. A neural network framework that executes its full mini-batch gradient descent loop entirely in C++, preventing the Python GIL from interrupting training epochs.

import numpy as np
import affineflow_nn as nn

X_train = np.random.rand(100, 1, 64, 64).astype(np.float32)
y_train = np.eye(40, dtype=np.float32)[np.random.choice(40, 100)]

class AffineFlowNNDeepCNN(nn.Module):
    def __init__(self, in_h, in_w, num_classes):
        super().__init__()
        self.conv1 = nn.Conv2dLayer(1, 16, in_h, in_w, kernel_size=5, stride=1, pad=2)
        self.act1 = nn.LeakyReLULayer(0.01)
        self.pool1 = nn.MaxPool2dLayer(16, in_h, in_w, kernel_size=2, stride=2, pad=0)
        
        out_h1, out_w1 = in_h // 2, in_w // 2
        self.conv2 = nn.Conv2dLayer(16, 32, out_h1, out_w1, kernel_size=3, stride=1, pad=1)
        self.act2 = nn.LeakyReLULayer(0.01)
        self.pool2 = nn.MaxPool2dLayer(32, out_h1, out_w1, kernel_size=2, stride=2, pad=0)
        
        out_h2, out_w2 = out_h1 // 2, out_w1 // 2
        self.flatten = nn.FlattenLayer()
        self.fc = nn.DenseLayer(32 * out_h2 * out_w2, num_classes)

    def forward(self, x):
        x = self.pool1(self.act1(self.conv1(x)))
        x = self.pool2(self.act2(self.conv2(x)))
        x = self.flatten(x)
        return self.fc(x)

model = AffineFlowNNDeepCNN(64, 64, 40)
optimizer = nn.Adam(learning_rate=0.001)
optimizer.set_parameters(model.parameters())
loss_fn = nn.SoftmaxCrossEntropyLoss()

trainer = nn.JITCompiler(model, optimizer, loss_fn)
dataloader = nn.DataLoader(X_train, y_train, batch_size=32, shuffle=True, drop_last=True)
trainer.fit(dataloader, epochs=40, verbose=False)
trainer.save_checkpoint("faces_model")

Architecture & Benchmarks

AffineFlow's core philosophy is Native Loop Hoisting. Rather than returning to Python after every matrix operation or epoch step, AffineFlow passes pointers to C++ once, executes the entire mathematical pipeline using AVX SIMD vectorization and a zero-allocation flat-memory Autograd graph, and returns only when finished.

Metadata

Release files for AffineFlow 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AffineFlow 0.1.3
File Size Uploaded Provenance
affineflow-0.1.3.tar.gz 6.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for AffineFlow 0.1.3
File Interpreter ABI Platform
affineflow-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / affineflow-0.1.3.tar.gz

Download URL affineflow-0.1.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c0628770f0fe8973a202fba0062db8cb8219d244acd978618c5aa3c1c3e2d7b1
BLAKE2b-256 checksum
How to use checksums
95a44f279c4664daea8deed99e1b3080073297ef628b0f56f8bc34833173fa53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release files / affineflow-0.1.3-py3-none-any.whl

Download URL affineflow-0.1.3-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd15d673e67413190f8e82f43ad933eed17f4370b2e26cbccfd3f6b31036687b
BLAKE2b-256 checksum
How to use checksums
9f9247dd2bfc8ba900a96d377ed7a320ea0f36bc376199fab8402b744e47e2dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Security for AffineFlow 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for affineflow-0.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page