Skip to main content

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

Project description

nblade - N-dimensional Blade

Crates.io 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 (up to 64D) and arbitrary metric signatures G(p, q, r).

Features

  • Arbitrary Dimensions: Up to 64-dimensional vector spaces
  • 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)

概述

nblade (N维 Blade) 是一个基于 Rust 实现的高性能几何代数库,提供 Python 绑定。支持任意维度(最高 64 维)和任意度量签名 G(p, q, r)。

特性

  • 任意维度: 支持最高 64 维向量空间
  • 任意签名: 支持 G(p, q, r) 度量签名(欧几里得、时空、共形等)
  • 高性能: Rust 后端,支持并行计算和 SIMD 优化
  • 双表示: 自动选择密集或稀疏表示
  • 完整运算: 所有标准几何代数运算
  • NumPy 集成: 直接从 NumPy 数组创建向量

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 python/tests/

Code Style

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

贡献

欢迎贡献!请参阅 CONTRIBUTING.md 了解贡献指南。

开发环境设置

# 克隆仓库
git clone https://github.com/UynajGI/nblade.git
cd nblade

# 安装 Rust(如果尚未安装)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# 构建
cargo build --release

# 运行测试
cargo test --all-features

# 构建 Python 绑定
pip install maturin
maturin develop --release

# 运行 Python 测试
pytest python/tests/

代码风格

  • Rust: 遵循 cargo fmtcargo clippy
  • Python: 遵循 PEP 8,使用 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.2.tar.gz (173.5 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.2-cp312-cp312-win_amd64.whl (276.1 kB view details)

Uploaded CPython 3.12Windows x86-64

nblade-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (354.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nblade-0.1.2-cp310-cp310-win_amd64.whl (274.1 kB view details)

Uploaded CPython 3.10Windows x86-64

nblade-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (353.7 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

nblade-0.1.2-cp38-cp38-win_amd64.whl (274.5 kB view details)

Uploaded CPython 3.8Windows x86-64

nblade-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (398.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

nblade-0.1.2-cp38-cp38-macosx_11_0_arm64.whl (354.4 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for nblade-0.1.2.tar.gz
Algorithm Hash digest
SHA256 397486ce067ea75473b012df25acd628a24f8aebaf6d88c5e89aaef77cbd9052
MD5 12811977cd18188bd59ccc916d0605aa
BLAKE2b-256 ebc5deb3f25e581e8bc8a7ec7c8cb628ebb3776efad846b94c4a41b5119f3c12

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for nblade-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4e94d7f02834dbe6ef340cd6a39eac6550f5773f6b1127e0fd56b4324901286a
MD5 a7c8110c4a128e65019d93accd166896
BLAKE2b-256 ac685f476dd045d066d4fb5c42567a47d9cb48aeb8b1a304259acc75bfc26a87

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae0ee829683d86b5df1d6ad7c587fd1e075a096a526979b4cfa0b19dd9243b19
MD5 d94a9b9effd8b083dccf6e7ce29c7755
BLAKE2b-256 08a78c77a515a9a133a86478028a4889281f46c9f7aa7630d0bef0fa4c3948b1

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for nblade-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bf681fcd9859c016b920087b1170d933060daed3bf7b2cbe92b545c4ad5bd989
MD5 8e46793e1bcd380d2553f6248708d5c2
BLAKE2b-256 31b5603f079b8ad86d839c21204123fa8ca10e5d418fb360a07a35e89fdefac7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a0e9fc390356d6a6de0c2c869b8e68c8f8704d6f9ec454633272b193a1b48bd7
MD5 a7687df1c816722db0d032ace980a374
BLAKE2b-256 3f28039f63a004fbec382663f10e0ece60fed61d2c563940180e5fabc5095845

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for nblade-0.1.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c1514f5fcf33f8abb670862f958ff57cd5a0eca88f34d5cb49179161bee390a2
MD5 6a59ed1f25531823dba7525c8734a925
BLAKE2b-256 b0dee876c02562a0f0acf27959ba586201579a27acbfbf3d2c4aae08c0c0987a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nblade-0.1.2-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.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nblade-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40364ed5b70003f92d13d55aea59b192734c6350b321d09efb7ec95412a6c207
MD5 05af5cc6f0dbfa746668c33e4f059dd1
BLAKE2b-256 339dcc6cf420a33b657b1da9beb7940eb698389bf5ebd85f570b1b3fa84285f9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nblade-0.1.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c758253c3ed58b7bc89e4696d703a8d378b15956d614c2d9ce8fb22a3d7677d5
MD5 abce0dc37502a8552aa6f8998a6d791f
BLAKE2b-256 7ffee92450aac80757a2e509c2f6716d0a217d529f2f84f9819edea62026456e

See more details on using hashes here.

Provenance

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