Skip to main content

A high-performance N-dimensional array library built in Rust for macOS.

Project description

🚀 Zanpy

Zanpy is a high-performance N-dimensional array library built in Rust with a seamless Python interface. It leverages SIMD (Single Instruction, Multiple Data) and cache-efficient memory layouts to provide blazing-fast linear algebra operations.


✨ Features

  • Native Rust Engine: Memory-safe, high-speed core implementation.
  • SIMD Acceleration: Matrix multiplication optimized with wide SIMD types (f64x2) and $i, k, j$ loop reordering.
  • N-Dimensional Support: Sophisticated broadcasting for arrays up to 8 dimensions.
  • Numpy-Compatible: Familiar Python syntax for reshape, transpose, arange, and identity.
  • Linear Algebra: Built-in LU decomposition for matrix inversion and dot product support.

📦 Installation

To install the latest release via pip:

pip install zanpy

Note: For local development, see the Development section.


🛠 Usage

Basic Array Creation

import zanpy

# Create a 2x2 identity matrix
identity = zanpy.PyNdArray.identity(2)

# Create an array from a range and reshape it
a = zanpy.PyNdArray.arange(0, 4, 1).reshape([2, 2])

Arithmetic & Broadcasting

b = zanpy.PyNdArray.ones([2, 2])

# Element-wise addition using the + operator
c = a + b

# Matrix Multiplication using the @ operator
d = a @ identity

Reductions & Math

print(f"Matrix Sum: {a.sum()}")
print(f"Matrix Mean: {a.mean()}")
print(f"Matrix Max: {a.max()}")

# Invert a square matrix
a_inv = a.inv()

🏗 Architecture

Zanpy is architected for speed by separating the math logic from the Python glue:

  1. zanpy-core: The standalone Rust crate. It manages the NdArray struct, calculating memory offsets via strides and executing raw SIMD math.
  2. zanpy-py: The bridge crate. Uses PyO3 and Maturin to expose Rust functionality as a Python module.

Why it's fast

The mat_mul implementation avoids the "cache-miss" penalty of naive triple-nested loops by using an $i, k, j$ traversal. This ensures that the CPU accesses memory in a linear, predictable fashion, maximizing cache hits.


🛠 Development

Prerequisites

  • Rust (1.70+ recommended)
  • Python (3.9+)
  • Maturin (pip install maturin)

Building from Source

# Clone the repository
git clone [https://github.com/yourusername/zanpy.git](https://github.com/yourusername/zanpy.git)
cd zanpy

# Compile and install in your current virtual environment
cd crates/zanpy-py
maturin develop --release

Testing

# Run Rust unit tests
cargo test

# Run Python integration tests
pytest tests/

📜 License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zanpy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (214.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file zanpy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zanpy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 147ba8d6ed77b69ecf91addc5542a3c40c6d8707be1dea901cd328f30061d451
MD5 a665e6c7b671a91d9aae4fe31e10ad8d
BLAKE2b-256 010e944863c9ca22e6c4ca1f6690885f14fb70af8f9dc10dd3ca3b436af85dba

See more details on using hashes here.

Provenance

The following attestation bundles were made for zanpy-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on Mersautschip/zanpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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