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.6-cp312-cp312-win_amd64.whl (281.5 kB view details)

Uploaded CPython 3.12Windows x86-64

nblade-0.1.6-cp312-cp312-macosx_11_0_arm64.whl (357.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nblade-0.1.6-cp310-cp310-win_amd64.whl (279.1 kB view details)

Uploaded CPython 3.10Windows x86-64

nblade-0.1.6-cp310-cp310-macosx_11_0_arm64.whl (356.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

nblade-0.1.6-cp38-cp38-macosx_11_0_arm64.whl (357.2 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: nblade-0.1.6-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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 73fa1347130d21b0305f41046cc8c5be70b9e088b78749b49f2fb5fa2bb956fe
MD5 6fd55871674d480547fa16c188f2cf67
BLAKE2b-256 0b63f557677f80b3581d9ab1928a4c1a7a299b9d90601e52a7a01ba4f6605299

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2fb8314c3be252d063f81b6886e022ac3475489e81fddb94f0d6560b9333282f
MD5 2d6c216bf34be3d6ad532040b6feb5b0
BLAKE2b-256 141c876db413d2cf87ae71a6245492552eb26223dd2e20d1661c2333301b7179

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nblade-0.1.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 279.1 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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6500213e8e08f9c4f0100883e36db452c59ceae5f012549315f12c74459169d0
MD5 bc158bcc058970765c3011306c20fe86
BLAKE2b-256 864a43c4bc902864dfbf169925ac53687db48fcf35cd51332b7b2143fa295076

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 02fb3f62b4e54adabe291ab907ddc1168ea1dabf400adf26c05b78a0f2d7fb56
MD5 8e1f9e025687afbcca3cfcc839228736
BLAKE2b-256 cc003bbd53a29fe1293ce7bc9b943ed4930c00c0e1f86867d5fc4fcb7a650ce7

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nblade-0.1.6-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.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c9e2547bc5e8f56a709eadf36cc39f4a5b2e124a6682df1bc4011733ee5209c7
MD5 82a36111e1155ca3bc19f6357453dd0f
BLAKE2b-256 d68060b25e1bed8791924056e8b382d851739b650e12f196109659d65bed8ed6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9d4928372d649ce7a777f206379676c59d744c23ab4f9a89a040d127e8587e8
MD5 a6325c8ad077cd10b5e33cf2ce49b919
BLAKE2b-256 e4e2151dd299221b42ddd3bd36d6e0dac42ec7c45a74b7e303ef991385ad05ff

See more details on using hashes here.

Provenance

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