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.0

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

Built distribution (wheel)

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

Total release size: 8.9 kB

Release files / affineflow-0.1.0.tar.gz

Download URL affineflow-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
61d8d3d5baac78810ac58ad496bc8ef2a3aa804ac8e42ab67c447df527c24fd2
BLAKE2b-256 checksum
How to use checksums
b5624fb2e29286662e6b480dcd7a5937966ddd8b5c557fd5b4d36586fabd89d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 29, 2026.

Transparency log

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

Download URL affineflow-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4a9b33ee13da1ea22b9eb7ac4e0eaadf14990963e01a37b5d007fcc3c41ead2
BLAKE2b-256 checksum
How to use checksums
48bb24744e06ae9efe232dd20230e079645301f86620e41c77e04656fba455ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 29, 2026.

Transparency log

Security for AffineFlow 0.1.0

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.0.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 Jul 29, 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