Skip to main content

A flexible linear operator abstraction in pytorch.

Project description

torch-named-linops

GitHub Actions Workflow Status Codecov PyPI - Version GitHub License

A flexible linear operator abstraction implemented in PyTorch.

Documentation

$ pip install torch-named-linops

Quick Example

import torch
from torchlinops import Dense, Diagonal, Dim

# Create operators with named dimensions
W = torch.randn(3, 7)
A = Dense(W, Dim("MN"), ishape=Dim("N"), oshape=Dim("M"))

# Apply, take adjoint, compose
x = torch.randn(7)
y = A(x)             # Forward: y = W @ x
z = A.H(y)           # Adjoint: z = W^H @ y
w = A.N(x)           # Normal:  w = W^H @ W @ x

# Compose operators with @
d = torch.randn(3)
B = Diagonal(d, ioshape=Dim("M"))
C = B @ A             # Chain: C(x) = diag(d) @ W @ x

See the Getting Started guide for a full walkthrough.

Selected Feature List

  • A dedicated abstraction for naming linear operator dimensions.
  • A set of core linops, including:
    • Dense
    • Diagonal
    • FFT
    • ArrayToBlocks1 (similar to PyTorch's unfold but in 1D/2D/3D/arbitrary dimensions)
      • Useful for local patch extraction
    • Interpolate1 (similar to SigPy's interpolate/gridding)
      • Comes with kaiser_bessel and first-order spline kernels.
  • .H and .N properties for adjoint $A^H$ and normal $A^HA$ linop creation.
  • Chain and Add for composing linops together.
  • Splitting a single linop across multiple GPUs.
  • Full support for complex numbers. Adjoint takes the conjugate transpose.
  • Full support for autograd-based automatic differentiation.

Documentation

The documentation is built using Zensical with tutorials authored as Marimo notebooks.

Building Documentation Locally

Install just (a command runner):

# Install with uv
uv tool install just

# Or with other package managers
# Homebrew: brew install just
# Cargo: cargo install just

Build the documentation:

# Build tutorials and documentation
just docs

# Or serve locally with auto-reload
just dev

Available commands:

Command Description
just tutorials Build tutorials from marimo notebooks
just docs Build full documentation (includes tutorials)
just serve Serve documentation locally
just dev Build and serve documentation

Editing Tutorials

Tutorials are marimo notebooks in tutorials/*.py. To edit:

# Edit a tutorial interactively
uv run marimo edit tutorials/basics.py

# Rebuild markdown after edits
just tutorials

Other Packages

This package was heavily inspired by a few other influential packages. In no particular order:

  • einops: named dimensions/naming things in general.
  • sigpy: the linop abstraction and the idea of having dedicated adjoint and normal properties. Also inspired the NUFFT, Interpolate, and ArrayToBlocks/BlocksToArray operators.
  • torch_linops: another linop abstraction. Geared more towards optimization.
  1. Includes a functional interface and triton backend for 1D/2D/3D. 2

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

torch_named_linops-0.7.0.tar.gz (330.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_named_linops-0.7.0-py3-none-any.whl (180.0 kB view details)

Uploaded Python 3

File details

Details for the file torch_named_linops-0.7.0.tar.gz.

File metadata

  • Download URL: torch_named_linops-0.7.0.tar.gz
  • Upload date:
  • Size: 330.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torch_named_linops-0.7.0.tar.gz
Algorithm Hash digest
SHA256 c7a7e4778c73d11a5d4136520c3b24f2946b3cf608f4b92880a05b019f0668ba
MD5 1bd6e86980b78a71f39b5d4312444f3f
BLAKE2b-256 0ab6d7d0787b9d05db8b9112ffe63f82cfca5c11db21b081283b15789ee99b74

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_named_linops-0.7.0.tar.gz:

Publisher: release.yml on nishi951/torch-named-linops

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torch_named_linops-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_named_linops-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10ac930d7ee0f767e4f4ff92c59e7d4f0fa81832f7cd16f9d40c32ab0f9448eb
MD5 51248273f7359ced876dd0add172f139
BLAKE2b-256 2d3478007a16ca42a0a3c0de5cfbd39b04074dd672e3565166320efc65c9147f

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_named_linops-0.7.0-py3-none-any.whl:

Publisher: release.yml on nishi951/torch-named-linops

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