Clifra: a differentiable Clifford algebra computation layer for PyTorch

Hi,

I’ve been working on clifra, a differentiable Clifford algebra computation layer for PyTorch.

The main design goal is to keep Clifford algebra inside the normal PyTorch programming model. Values are ordinary torch.Tensors; layouts describe what their coefficient axis means, while leading dimensions remain ordinary PyTorch dimensions for batching, broadcasting, spatial structure, or anything else the application needs. PyTorch continues to own autograd, modules, devices, and tensor composition.

import torch
from clifra import make_algebra

algebra = make_algebra(3, 0)

vectors = algebra.layout((1,))
product = algebra.plan_product(
    left=vectors,
    right=vectors,
    output=algebra.layout((0, 2)),
)

left = torch.randn(8, vectors.dim, requires_grad=True)
right = torch.randn(vectors.dim)

out = product(left, right)
out.square().mean().backward()

Here the inputs are just tensors containing vector coefficients in Cl(3,0). The output layout requests the scalar and bivector parts of their geometric product. The leading dimension broadcasts normally, and gradients flow through the tensor computation without a separate multivector runtime.

A second part of the design is planned execution. Clifford operations often have structure that is fixed independently of coefficient values: the algebra signature, input/output grades, storage layout, and the basis interactions implied by them. clifra can resolve that structure once into a reusable nn.Module, while coefficient values and leading tensor dimensions stay dynamic.

That gives a fairly unified model:

geometric structure → planned operation → ordinary PyTorch tensor execution

The same abstraction covers products, projections and involutions, reflections, bivector exponentials, and bivector-generated actions. Internally, some of these operations have several quite different algorithms available, but those implementation choices remain behind the mathematical interface rather than becoming user-facing performance knobs.

As one example of using this abstraction beyond isolated algebraic operations, I’ve been experimenting with continuous-time PGA LiDAR deskewing. Acquisition time acts as a persistent sample coordinate, and a differentiable field of local Clifford generators is optimized from sparse geometric constraints to recover the sensor motion and deskew the scan. The field machinery itself is ordinary PyTorch code around planned Clifford actions.

The repository contains a few other research experiments built on the same idea, but they are kept outside the stable library core.

Docs: clifra
GitHub: GitHub - Concode0/clifra: clifra is a differentiable Clifford algebra computation layer for PyTorch. · GitHub

I’d be interested in feedback on whether the ordinary tensors + explicit layouts + planned operations model feels natural from a PyTorch user’s perspective.