Skip to main content

N-dimensional Blade - High-performance Geometric Algebra library powered by Rust

Project description

nblade - N-dimensional Blade

PyPI Docs License: MIT zread

English | 中文 | Documentation | 文档


Overview

nblade (N-dimensional Blade) is a high-performance geometric algebra library powered by Rust, with Python bindings. It supports arbitrary dimensions and arbitrary metric signatures G(p, q, r).

Features

  • Arbitrary Dimensions: Up to 64-dimensional vector spaces (practical limit ~12D for dense operations)
  • Arbitrary Signatures: Support for G(p, q, r) metric signatures (Euclidean, spacetime, conformal, etc.)
  • High Performance: Rust backend with parallel computing and SIMD optimization
  • Dual Representation: Automatic selection of dense or sparse representation
  • Complete Operations: All standard geometric algebra operations
  • NumPy Integration: Create vectors directly from NumPy arrays

Installation

Python

pip install nblade

From Source

# Install maturin
pip install maturin

# Build and install
maturin develop --release

Quick Start

import nblade

# Create 3D Euclidean geometric algebra G(3,0,0)
algebra = nblade.Algebra.euclidean(3)

# Create basis vectors
e1 = algebra.basis_vector(0)
e2 = algebra.basis_vector(1)
e3 = algebra.basis_vector(2)

# Create a vector from a list
v = algebra.vector([1, 2, 3])

# Geometric product
product = e1 * e2  # Results in bivector e12

# Outer product (wedge product)
wedge = e1 ^ e2  # Results in bivector e12

# Inner product
inner = e1 | e2  # Results in 0 (orthogonal vectors)

# Dual
I = algebra.config.volume_element()  # Pseudoscalar
v_dual = v.dual()

# Rotation using rotor
import math
plane = e1 ^ e2
rotor = algebra.rotor(plane, math.pi / 2)  # 90-degree rotation
rotated = e1.rotate_by(rotor)

API Reference

Algebra Class

algebra = nblade.Algebra(dimension, p=0, q=0, r=0)

# Factory methods
algebra = nblade.Algebra.euclidean(dimension)  # G(n, 0, 0)
algebra = nblade.Algebra.spacetime(dimension)  # G(1, n-1, 0)
algebra = nblade.Algebra.cga()                 # G(4, 1, 0)

# Properties
algebra.dimension   # Vector space dimension
algebra.signature   # (p, q, r) tuple

# Methods
algebra.basis_vector(i)      # Create e_i
algebra.vector([x, y, z])    # Create vector from list
algebra.scalar(value)        # Create scalar multivector
algebra.zeros()              # Create zero multivector
algebra.one()                # Create unit scalar
algebra.rotor(plane, angle)  # Create rotor

MultiVector Class

# Construction
mv = nblade.MultiVector.basis_vector(config, i)
mv = nblade.MultiVector.from_scalar(config, value)
mv = nblade.MultiVector.from_coefficients(config, coeffs)
mv = nblade.MultiVector.zeros(config)
mv = nblade.MultiVector.one(config)

# Products
mv.geometric_product(other)  # Geometric product
mv.outer_product(other)      # Outer/wedge product
mv.left_inner(other)         # Left contraction
mv.right_inner(other)        # Right contraction

# Involutions
mv.grade_involution()        # Grade involution (A*)
mv.reversion()               # Reversion (A†)
mv.clifford_conjugate()      # Clifford conjugate (A‡)

# Other operations
mv.dual()                    # Dual (A⊥)
mv.inverse_dual()            # Inverse dual (A⁻⊥)
mv.inverse()                 # Multiplicative inverse
mv.norm()                    # Norm |A|
mv.norm_squared()            # |A|²

# Grade operations
mv.grade(r)                  # r-grade part
mv.even_part()               # Even grades
mv.odd_part()                # Odd grades

# Geometric operations
mv.project_to(blade)         # Project onto blade
mv.reject_from(blade)        # Reject from blade
mv.reflect_in(blade)         # Reflect in blade
mv.rotate_by(rotor)          # Rotate by rotor

# Operator overloads
mv1 + mv2   # Addition
mv1 - mv2   # Subtraction
mv1 * mv2   # Geometric product
mv1 ^ mv2   # Outer product
mv1 | mv2   # Left inner product
~mv        # Grade involution
-mv        # Negation

Module Functions

# Create rotor for rotation in a plane
rotor = nblade.create_rotor(plane, angle)

# Reciprocal frame computation
reciprocal = nblade.reciprocal_frame(vectors)

# Basis expansion
coeffs = nblade.basis_expansion(multivector)

Supported Operations

Operation Symbol Formula
Geometric Product AB AB = A·B + A∧B
Outer Product A∧B Antisymmetric part
Left Inner A⌋B Left contraction
Right Inner A⌊B Right contraction
Grade Involution A* (-1)^r A_r
Reversion A† (-1)^(r(r-1)/2) A_r
Clifford Conjugate A‡ (A*)†
Dual A⊥ A·I or AI
Inverse Dual A⁻⊥ A⌋I

Performance

nblade is optimized for performance:

  • SIMD acceleration for 2D-4D operations (with simd feature)
  • Adaptive parallelism for high-dimensional operations (≥6D)
  • Memory pooling for reduced allocation overhead (with pool feature)
  • Dense/Sparse auto-selection based on coefficient density

Benchmarks

Operation Dimension Time
Geometric Product 3D ~5ms
Geometric Product 5D ~15ms
Geometric Product (SIMD) 3D ~3ms

Examples

2D Rotation

import nblade
import math

# Create 2D Euclidean algebra
algebra = nblade.Algebra.euclidean(2)

# Create basis vectors
e1, e2 = algebra.basis_vectors()

# Create rotor for 45-degree rotation
plane = e1 ^ e2
rotor = algebra.rotor(plane, math.pi / 4)

# Rotate e1
rotated = e1.rotate_by(rotor)
print(rotated)  # ~ 0.707*e1 + 0.707*e2

3D Cross Product via Dual

import nblade

algebra = nblade.Algebra.euclidean(3)
e1, e2, e3 = algebra.basis_vectors()

# Cross product: a × b = (a ∧ b)*
# where * is the dual in 3D

a = e1 + 2*e2
b = 2*e1 + e3

# Compute cross product
a_cross_b = (a ^ b).dual()
print(a_cross_b)

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone the repository
git clone https://github.com/UynajGI/nblade.git
cd nblade

# Install Rust (if not already)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build
cargo build --release

# Run tests
cargo test --all-features

# Build Python bindings
pip install maturin
maturin develop --release

# Run Python tests
pytest tests/test_python_api.py

Code Style

  • Rust: Follow cargo fmt and cargo clippy
  • Python: Follow PEP 8, use ruff format

License

MIT License

Project details


Download files

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

Source Distribution

nblade-0.1.5.tar.gz (177.4 kB view details)

Uploaded Source

Built Distributions

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

nblade-0.1.5-cp312-cp312-win_amd64.whl (279.1 kB view details)

Uploaded CPython 3.12Windows x86-64

nblade-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (355.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nblade-0.1.5-cp310-cp310-win_amd64.whl (276.6 kB view details)

Uploaded CPython 3.10Windows x86-64

nblade-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (354.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

nblade-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (399.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

nblade-0.1.5-cp38-cp38-win_amd64.whl (276.9 kB view details)

Uploaded CPython 3.8Windows x86-64

nblade-0.1.5-cp38-cp38-macosx_11_0_arm64.whl (355.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

Details for the file nblade-0.1.5.tar.gz.

File metadata

  • Download URL: nblade-0.1.5.tar.gz
  • Upload date:
  • Size: 177.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nblade-0.1.5.tar.gz
Algorithm Hash digest
SHA256 c96ddc67b0a7468d1c1a5a1c6f125fcd4e754794d6ebaf2108db349ff172e934
MD5 077ed1cc13decbd4263c1a746568d981
BLAKE2b-256 95a64a37d54b9e137d72f85bd63cfed4b9bd473f5309db74ed21709e076973e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5.tar.gz:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 279.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nblade-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fa5ad5a777ae20957b3970c2b4bb78532d7f2a8e2df105c2ec9a31717d50b4e1
MD5 027317435cafd4e18a9da0738318d5c8
BLAKE2b-256 6662b2fbfb8a5ceb85a20a2fc96b0e66da8d585941538fd6082648e3746d2d15

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp312-cp312-win_amd64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 612d0f920d4f1cc58e5f7ee429345bb4f000df428b1cb3e1a6e77642b34aa41d
MD5 3543dd2367523b3b8e4da0e4fb245554
BLAKE2b-256 7b10f33a915ba2a5e5d17e04578c900ab04a4b5b999297a8e1a611a9b4a1fe67

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 276.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nblade-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dac45be2357467f9ed0c29d1161b6b5907f327b5b9c2c27fe95ffd1799a337b2
MD5 34d6b9f92df5867440f17174f907af39
BLAKE2b-256 30e5ba78778608a81bd910e19f377ef3c8d71449a340d9d5980487cc7eb02461

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp310-cp310-win_amd64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cbdbb75ae68306cbd83393ecae69ba72333c8387a126287bbba2804bcf87f29c
MD5 6cbe56f2fcc0220e73ffaee553509794
BLAKE2b-256 07061ab107fca526a7d2680fdda1c9fcb81f5bd949bf6dc03e1748f61209c38f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nblade-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 589bd5dc04662acd57014dea5267a2efc33c97b4af1a861ff43ef1a66672510e
MD5 97029e54cd93fac894bc5988d813321e
BLAKE2b-256 223966fed31ecd468a423613c03b4e8f5242fbe1f81b059c875f5ed15d507ce0

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 276.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nblade-0.1.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 063ad4afd184a26f41ec64f1855362462b1fa2fca66281572edd614637eea726
MD5 874ac24daad10945dbae689645f5cfc6
BLAKE2b-256 3ed6496c5be6b1c0788f75e85fd7c87bcf526baef611cef58c4bfb1a7dcec43d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp38-cp38-win_amd64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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

File details

Details for the file nblade-0.1.5-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6388b62889adf295bd726bc72f976d20c576096505eb154db91cefeea2c7bc11
MD5 5472b4e6c9d1cfd956e1a111d34f9abb
BLAKE2b-256 a54812b7e43c26dd2ce664fcb47a045a1b706316fcd162edc8310e0f20e94987

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.5-cp38-cp38-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on UynajGI/nblade

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