Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

FastQuat - High-Performance Quaternions with JAX

PyPI version Python versions License Documentation Status CI Ruff

FastQuat provides optimized quaternion operations with full JAX compatibility, featuring:

  • 🚀 Hardware-accelerated computations (CPU/GPU/TPU)
  • 🔄 Automatic differentiation support
  • 🧩 Seamless integration with JAX transformations (jit, grad, vmap)
  • 📦 Efficient storage using interleaved memory layout

Installation

pip install fastquat

This will install FastQuat with CPU support. For GPU support, you may need to install JAX with CUDA support:

pip install "jax[cuda12]" fastquat

Quick Start

import jax.numpy as jnp
from fastquat import Quaternion

# Create quaternions
q1 = Quaternion(1)  # Identity quaternion
q2 = Quaternion(0.7071, 0.7071, 0.0, 0.0)  # 90° rotation around x-axis
q = Quaternion(1.0, 0.1, 0.2, 0.3)
p = 2

# Arithmetic
q_sum = q1 + q2
q_diff = q1 - q2
q_product = q1 * q2
q_power = q**p

# Comparison (element-wise)
same = q1 == q2  # Boolean array, True where all components are equal

# Normalization
norm = abs(q)  # Quaternion norm
q_unit = q.normalize()  # Unit quaternion

# Conjugation and inverse
q_conj = q.conj()  # Conjugate
q_inv = 1 / q  # Inverse, or q ** -1

# Other operations
q_log = q.log()
q_exp = q.exp()

# Rotate vectors
vector = jnp.array([1.0, 0.0, 0.0])
rotated = q2.rotate_vector(vector)

# Spherical interpolation (SLERP)
interpolated = q1.slerp(q2, t=0.5)  # Halfway between q1 and q2

Features

Core Operations

  • Quaternion arithmetic: Addition, multiplication, conjugation, inverse, power, exponentiation, logarithm
  • Normalization: Efficient unit quaternion computation
  • Comparison: Element-wise == and !=, like NumPy arrays
  • Conversion: To/from rotation matrices, axis-angle, rotation vectors, Euler angles
  • Vector rotation: Direct vector transformation

Advanced Interpolation

  • SLERP (Spherical Linear Interpolation): Smooth rotation interpolation
    • Automatically handles shortest path selection
    • Numerically stable for close quaternions
    • Supports batched operations and array-valued parameters

JAX Integration

  • JIT compilation: Compile quaternion operations for maximum performance
  • Automatic differentiation: Compute gradients through quaternion operations
  • Vectorization: Process batches of quaternions efficiently
  • Device support: Run on CPU, GPU, or TPU

Performance

FastQuat is optimized for high-performance computing:

  • Memory-efficient interleaved storage
  • SIMD-optimized operations on supported hardware
  • Zero-copy integration with JAX arrays
  • Minimal Python overhead through JIT compilation

Examples

Basic Usage

import jax
import jax.numpy as jnp
from fastquat import Quaternion

# Create random quaternions
key = jax.random.PRNGKey(42)
q_batch = Quaternion.random(key, shape=(1000,))


# JIT-compiled batch operations
@jax.jit
def batch_rotate(quaternions, vectors):
    return quaternions.rotate_vector(vectors)


vectors = jax.random.normal(key, (1000, 3))
rotated_batch = batch_rotate(q_batch, vectors)

SLERP

# Smooth rotation interpolation
q_start = Quaternion(1.0)
q_end = Quaternion.from_rotation_matrix(rotation_matrix)

# Generate smooth interpolation
t_values = jnp.linspace(0, 1, 100)
interpolated_rotations = q_start.slerp(q_end, t_values)

# Apply to object vertices for smooth animation
animated_vertices = interpolated_rotations.rotate_vector(object_vertices)

Documentation

Full documentation is available at fastquat.readthedocs.io

Contributing

Contributions are welcome! Please see our development guide for details.

License

MIT License - see LICENSE file for details.

Metadata

Release files for FastQuat 1.0b7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FastQuat 1.0b7
File Size Uploaded
fastquat-1.0b7.tar.gz 181.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for FastQuat 1.0b7
File Interpreter ABI Platform
fastquat-1.0b7-py3-none-any.whl Python 3 none any Details

Total release size: 193.1 kB

Release files / fastquat-1.0b7.tar.gz

Download URL fastquat-1.0b7.tar.gz
Size 181.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b1c459a14ba7e96c30476486d1ed7f6dc0d49d83f16f6c0682bd26e2a794f161
BLAKE2b-256 checksum
How to use checksums
0d1372eb920f06ed04d93c074383d875d883d0fcab4b95e6cab51de5a87525ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release files / fastquat-1.0b7-py3-none-any.whl

Download URL fastquat-1.0b7-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae317462d376e6778f77c6748d8e26c85aaae724aa658bb0e053bb6eac7d78b9
BLAKE2b-256 checksum
How to use checksums
f26919b59ae7e1368df98b315b276b6890a79e86ac861847d7eb20bc4a8f0802
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page