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 Distribution

nblade-0.1.8.tar.gz (180.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.8-cp312-cp312-win_amd64.whl (281.5 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

nblade-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (402.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8Windows x86-64

nblade-0.1.8-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.8.tar.gz.

File metadata

  • Download URL: nblade-0.1.8.tar.gz
  • Upload date:
  • Size: 180.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.8.tar.gz
Algorithm Hash digest
SHA256 a7ce26be3ad171d176105a9223592de9b151ebe9e30758aa8185ceaf2aa65538
MD5 e62dfdd4734d2ac21850fe3db7c945f6
BLAKE2b-256 ca1fa8d8e413756d34ba61a1d1de275ca35a5e1c82662872352b120b9e701593

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.8.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.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nblade-0.1.8-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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b66f23a28ae49b023867321bfec2c23f69c08c4b32ed54a53d8aab39ac8f1121
MD5 45c69a330246c1fe075f383b4f0991b4
BLAKE2b-256 85c03276ec04b0b02fc7708b8e33522f43a0eb21fcbc2b51f8a347026137e7d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 020f81a8daec59291b5d33eee4ea54500a335ff420ef105fa658ecfec37984f0
MD5 6c908cbf6e68a2c9937dfb337ebe1160
BLAKE2b-256 90748c5dec48f241f1d9237d6039229b4d6daba2863750c0775a47e1d2b14786

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nblade-0.1.8-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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d42e5294ca8706744d493dd1017118001fda9da3785b5267b0627ba55fbd3bbf
MD5 952bd5c270ab1413ddc1c1caff52aac6
BLAKE2b-256 7d28a2f58cb395f5bbe047b678cbf0189d95e44b52f2ce9ede201894be90b9ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6958dbcde8ecff73e0630ba7508d66538926bb2449a11b2ebe8ff01a5928e1cd
MD5 b4909ab4e51ff46857cfc9a0d71ae3ec
BLAKE2b-256 1306b02db847f77690a1c3b4dc457ea4fd2289d62aab6e8eea540f9e6e7a11d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.8-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.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nblade-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1b5b6ca6847ccd96a2fe2e46ee2996549ed2163168eba800ef8e74079b5c77c
MD5 4260771c0ed56969c743d9d554dfdc71
BLAKE2b-256 9db6dcd77b8bf925c558f198ce3764552c5059bb99ae03fe8ef754d46677e4ab

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nblade-0.1.8-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.8-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b362f6dcb278dae1ee13289ea7227f9786eb2c7ab1e7549f51791c825692dde2
MD5 e04601b14c5d5b0ab12d1e3963908981
BLAKE2b-256 a7d84c13785a336a9d4390c9eb89060e3d5df808c469709e49a6741b6d7551c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.8-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9eb58b7ce324308bd84cc90132bec919687f96f53a12e58475d228555d5fdbb8
MD5 c8e87d746bc717f1a06d19a1329612de
BLAKE2b-256 7c598c954ac452235fbc959e73d7ffef24ba70007573178ae95eabd49423fdac

See more details on using hashes here.

Provenance

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