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* (Python: ~A) (-1)^r A_r
Reversion A† (Python: A.reversion()) (-1)^(r(r-1)/2) A_r
Clifford Conjugate A‡ (Python: A.clifford_conjugate()) (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 Distributions

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

Built Distributions

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

nblade-0.1.7-cp312-cp312-win_amd64.whl (281.5 kB view details)

Uploaded CPython 3.12Windows x86-64

nblade-0.1.7-cp312-cp312-macosx_11_0_arm64.whl (357.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nblade-0.1.7-cp310-cp310-win_amd64.whl (279.2 kB view details)

Uploaded CPython 3.10Windows x86-64

nblade-0.1.7-cp310-cp310-macosx_11_0_arm64.whl (356.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

nblade-0.1.7-cp38-cp38-win_amd64.whl (279.5 kB view details)

Uploaded CPython 3.8Windows x86-64

nblade-0.1.7-cp38-cp38-macosx_11_0_arm64.whl (357.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: nblade-0.1.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 281.5 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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6b7492d7f9eaeaa9f24af1c8a99aa6fe5e3e5049bc882dc1baec8dedc2116478
MD5 e3edd743793f7e83fd3ce86d66f224c2
BLAKE2b-256 e4f692135952d13bc3fe881af58618b1f9ff90abdf94b1f9500864d55f364307

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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.7-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d67d401ffd00ce305286acbeeb6cb0118b32005766e448b30812ac2da81f4b8f
MD5 0243178e1e2ce80c96535fed2669e22d
BLAKE2b-256 a4d31825eea2df3921743885230b1b1e922878decd2ee8cb3ff5dee8d14606c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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.7-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 279.2 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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3fb0b7acbc470159bcc5df828ddbf42a460bd3e0ac3ea37adad4c4a3d6b83467
MD5 4f17d4ce90be5a6975e9c5667dab8a1e
BLAKE2b-256 e6ed0b490e3157929ba0eacca13ebaef3abbc7ed63acda7926df52caed9cf5d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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.7-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8933024d7d943b8ddf2df99080b6769ec714ed1e7d8311f12b93342bb008933e
MD5 559253f024ea90e15d9711055ecb3aa5
BLAKE2b-256 dec028ed529795eec5a2de3dc7dd67ced39f21fc998157f9ddb4603a7d79f0f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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.7-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 279.5 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.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 08d175a5f5dfd7c8e52736d019691f55786861d20991d7e47ca929a6908f3f40
MD5 86c2acb0f637c45912645b4d22bfc76a
BLAKE2b-256 f6356ecf63aad25aa6182842f3b3861a9e0776d67d5a0e9ff594d05c4c77ddfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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.7-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nblade-0.1.7-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52979460f0ff63a0668e6432d6907e1a86e865d069641f90669d4d3eaedfcfe2
MD5 f9454346b5744c9924d55400970cd7b1
BLAKE2b-256 33613239da6461ca98320a9a121ae96bb92d6faac7b7318da4bd7b1ef842d092

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.7-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