Skip to main content

Linear operators interfaces

Project description

aljabr — Implicit linear operators

aljabr is a small Python library providing an interface for implicit linear operators: linear maps defined by forward and adjoint callables rather than an explicit matrix. It is useful when an explicit matrix representation is not adequate — for instance when the dimension is large, when a more efficient algorithm exists, or when the operator is naturally expressed as a function.

A typical example is the Discrete Fourier Transform, which is a linear operator available through fft and ifft functions. aljabr lets you treat it — and compose it with others — as if it were a matrix.

The foundation is the LinOp type. Everything else — concrete operators, utilities, algebraic composition — is built on top of it and optional. I made this library for my own use.

Key differences from similar tools

vs. scipy.sparse.linalg.LinearOperator — input and output arrays can have any shape, not just vectors. A 2D FFT operator maps an image to an image. Shapes are fixed at construction: a DFT on a 512² image is a different object than one on a 256² image. This is intentional.

vs. PyLops — aljabr is deliberately minimal. It does not provide solvers or choose algorithms for you. There is no x = A / y. It stays out of your way, offering only readability and convenience.

Features

  • Abstract base class LinOp with forward (A·x) and adjoint (Aᴴ·y)
  • Algebraic composition: A + B, A - B, A @ B, scalar * A, A.H, A.S
  • Array-API compatible — works with NumPy, PyTorch, JAX, and others via array-api-compat
  • Compatible with scipy.sparse.linalg.LinearOperator — can also be passed directly as argument
  • Concrete operators: Identity, Diag, DFT, RealDFT, Conv, DirectConv, CircConv, FreqFilter, Diff, Sampling, Slice, wavelet, …
  • Utilities: dottest, fwadjtest, is_sym, is_pos_def, cond, …

Installation

aljabr is not yet on PyPI. Install directly from the repository:

# with uv (or poetry)
uv add "git+https://github.com/forieux/aljabr.git"

# with pip
pip install "git+https://github.com/forieux/aljabr.git"

Optional dependencies:

pip install aljabr[wavelet]   # PyWavelets — required for DWT, Analysis2, Synthesis2
pip install aljabr[scipy]     # SciPy — required for DirectConv and fcond

Quick example

import numpy as np
import aljabr

# Wrap the FFT as a linear operator
F = aljabr.DFT(shape=(256, 256), ndim=2)

x = np.random.randn(256, 256)
y = F.forward(x)        # F·x
z = F.adjoint(y)        # Fᴴ·y

# Algebraic composition
A = aljabr.Diff(axis=0, ishape=(256, 256))
B = A.H @ A             # AᴴA as a Symmetric operator

# Validate with the dot test
from aljabr import dottest
assert dottest(A, num=5)

Documentation

https://aljabr.readthedocs.io

Status

Pre-Alpha. The API may change. Feedback welcome: francois.orieux@universite-paris-saclay.fr

License

MIT — see 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

aljabr-0.5.0.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

aljabr-0.5.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file aljabr-0.5.0.tar.gz.

File metadata

  • Download URL: aljabr-0.5.0.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for aljabr-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f9ce19585a850101e05111dd515256792c31d6d8792f2f8e17db5b99d530b40f
MD5 4f76ddd3c776b8d1946e585ad71a877c
BLAKE2b-256 d65a4b31363bfc13ab24d2716f1b2a7d8d5d265d7a6aa4d18a9f4f8dabdcacfc

See more details on using hashes here.

File details

Details for the file aljabr-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: aljabr-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for aljabr-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b0e9d7a37de3b8e3968a7a05f19ba2821c4092e2415c953c9fa2db94b42c896
MD5 315d16668a94a75a5d5ed9d8eda4b3a8
BLAKE2b-256 b2df0563d7f48801a740200fa0532ec58424040b6dadf3edb6af4e8a173bef4e

See more details on using hashes here.

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