Catalog PyPI
PACKAGE EXPLORERView in registry

affine-rs

PyPI

Fast 3D affine transformations with trilinear interpolation using AVX2/AVX512 SIMD

affineavx2image-processinginterpolationnumpysimd
Versions collected1
Direct dependencies1From release 0.2.0
Last observed20 Oct, 21:04 UTC

README

Version 0.2.0 documentation

affiners

Fast 3D affine transformations with trilinear interpolation using AVX2/AVX512 SIMD.

Performance

Data TypeThroughputMemory/VoxelSpeedup
f321.5 Gvoxels/s8 bytes1.0x
f161.2 Gvoxels/s4 bytes-
u83.3 Gvoxels/s2 bytes2.2x

Use u8 for image data (microscopy, CT, MRI) to get 2.2x faster processing with 4x less memory!

Performance vs scipy

Benchmark on AMD Ryzen 9 9950X (32 threads):

Volumescipyaffiners f32affiners u8Speedup (f32)Speedup (u8)
512³890 ms89 ms40 ms10x22x
1024³7.1 s710 ms320 ms10x22x

Installation

pip install affine-rs

Or build from source:

pip install .

Usage

Python

import numpy as np
import affiners

# Define transformation
matrix = np.array([
    [1.0, 0.25, 0.01],
    [0.0, 1.0, 0.0],
    [0.0, -0.02, 1.0],
], dtype=np.float64)
offset = np.array([-10.0, -5.0, 8.0])

# Float32 data
input_f32 = np.random.rand(512, 512, 512).astype(np.float32)
output_f32 = affiners.affine_transform(input_f32, matrix, offset=offset)

# uint8 data (2.2x faster!)
input_u8 = np.random.randint(0, 256, (512, 512, 512), dtype=np.uint8)
output_u8 = affiners.affine_transform_u8(input_u8, matrix, offset=offset)

Check Build Info

import affiners

print(affiners.__version__)  # '0.1.0'
print(affiners.build_info())
# {'version': '0.1.0', 'simd': {'avx2': True, 'avx512f': True, ...}, 
#  'backend_f32': 'avx512', 'backend_u8': 'avx2', 'num_threads': 32, ...}

Rust

use ndarray::Array3;
use affiners::{affine_transform_3d_f32, affine_transform_3d_u8, AffineMatrix3D};

// Float32
let input_f32 = Array3::<f32>::zeros((100, 100, 100));
let matrix = AffineMatrix3D::identity();
let shift = [10.0, 20.0, 30.0];
let output_f32 = affine_transform_3d_f32(&input_f32.view(), &matrix, &shift, 0.0);

// uint8 (2.2x faster!)
let input_u8 = Array3::<u8>::zeros((100, 100, 100));
let output_u8 = affine_transform_3d_u8(&input_u8.view(), &matrix, &shift, 0);

API Reference

Python

FunctionInput TypeDescription
affine_transform(input, matrix, offset, cval)float32Standard floating point
affine_transform_f16(input, matrix, offset, cval)float16Half precision (pass as .view(np.uint16))
affine_transform_u8(input, matrix, offset, cval)uint82.2x faster, 4x less memory
build_info()-Get version, SIMD features, and backend info

Parameters

  • input: 3D numpy array (C-contiguous)
  • matrix: 3x3 transformation matrix (float64)
  • offset: Translation vector [z, y, x] (optional, default: [0, 0, 0])
  • cval: Constant value for out-of-bounds (default: 0)

When to Use Each Type

Use CaseRecommended Type
Image data (CT, MRI, microscopy)u8 - 2.2x faster
Scientific floating-point dataf32
Reduced memory footprintf16 or u8
Maximum precisionf32

Memory Requirements

Volume Sizef32u8
512³1.1 GB0.3 GB
1024³8.6 GB2.1 GB
2048³68.7 GB17.2 GB

Features

  • AVX2/AVX512 SIMD: Processes 8-16 values per iteration
  • Multi-threaded: Uses rayon for parallel z-slice processing
  • Memory efficient: u8 uses 4x less memory than f32
  • Python bindings: Via PyO3 and maturin
  • Zero-copy: Works directly with numpy arrays
  • Native compilation: Optimized for host CPU features (target-cpu=native)

License

BSD-3-Clause

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.04 Dec 20251

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:04 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f596ed489dfe8ac98a9a5dfe78c213cca2749e485854f985301a65836a8f665d