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 (knn-engine-core and nn-engine-core). 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.knn

Powered by knn-engine-core. Features a highly optimized K-Nearest Neighbors classifier with built-in native Principal Component Analysis (PCA) for dimensionality reduction.

import numpy as np
import affineflow as af

X_train = np.random.rand(100, 64)
y_train = [str(i % 5) for i in range(100)]

# Configure Engine
cfg = af.knn.KNNConfig()
cfg.k = 3
cfg.variance = 0.95 # Retain 95% variance via native PCA

engine = af.knn.KNNEngine(cfg)
engine.train(X_train, y_train, scale=True)

predictions = engine.predict_batch(X_train[:5])
print("KNN Predictions:", predictions)

2. affineflow.nn

Powered by nn-engine-core. A multi-layer perceptron 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 as af

# Note: AffineFlow Neural Nets are hardware-optimized for 32-bit floats
X_train = np.random.rand(100, 4).astype(np.float32)
y_train = np.eye(3)[np.random.choice(3, 100)].astype(np.float32) 
dataloader = af.nn.DataLoader(X_train, y_train, batch_size=16)

# Build Architecture
class MyModel(af.nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = self.add_module(af.nn.DenseLayer(4, 16))
        self.relu = self.add_module(af.nn.ReLULayer())
        self.fc2 = self.add_module(af.nn.DenseLayer(16, 3))

    def forward(self, tape, x):
        x = self.fc1(tape, x)
        x = self.relu(tape, x)
        return self.fc2(tape, x)

model = MyModel()

# Compile & Train using C++ JIT
optimizer = af.nn.Adam(learning_rate=0.01)
loss_fn = af.nn.SoftmaxCrossEntropyLoss()
trainer = af.nn.JITCompiler(model, optimizer, loss_fn)

# C++ Native Training Loop
trainer.fit(dataloader, epochs=150, verbose=True)

# predict() returns raw logits. Use np.argmax for classification!
logits = model.predict(X_train[:1])
print("Neural Net Logits:", logits)

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.

In standard academic benchmarks (Iris, MNIST Digits, Olivetti Faces), affineflow.nn consistently achieves up to a 100x speedup over Scikit-Learn while maintaining mathematically identical (or superior) accuracy via Log-Sum-Exp fusion.

Metadata

Release files for AffineFlow 0.1.1

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.1
File Size Uploaded Provenance
affineflow-0.1.1.tar.gz 4.2 kB With provenance Details

Built distribution (wheel)

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

Total release size: 8.9 kB

Release files / affineflow-0.1.1.tar.gz

Download URL affineflow-0.1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
114131f13b6a5aaffae12c299c73bd369450cfc3ed561946a369d9edffc5f5e8
BLAKE2b-256 checksum
How to use checksums
8c050ac807a34726bcc804ff6016b42555c777c58d5c4cffae520c30991e2cce
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 3, 2026.

Transparency log

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

Download URL affineflow-0.1.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6dc29ac6a227d3c2e0a28e5267f2432c8f5bc373c9ee974c6142e68315dfffff
BLAKE2b-256 checksum
How to use checksums
71c14d57e964286d641e1c8d1bf859645a44ef073c1fadf3b749e21627582479
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 3, 2026.

Transparency log

Security for AffineFlow 0.1.1

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.1.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 3, 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