skillfed

linear-operator

A linear operator implementation, primarily designed for finite-dimensional positive definite operators (i.e. kernel matrices).

linear-operator v0.6.1 1.1M downloads/30d#4,309 on PyPI126
Permissive license MIT Active released

What it is and what it does

LinearOperator is a PyTorch package that lets you define and work with structured matrices—such as low-rank-plus-diagonal or triangular matrices—without explicitly constructing them as dense tensors. Instead of materializing a large matrix in memory, you define it compositionally (e.g., `LowRankRootLinearOperator(C) + DiagLinearOperator(d)`) and LinearOperator automatically routes operations like solves and matrix-vector products through efficient structure-exploiting routines. It depends on torch and scipy and integrates with PyTorch's standard linear algebra API.

The package is currently in beta and supports positive semi-definite and triangular matrices. Its main value is enabling memory-efficient and computationally efficient workflows for large structured matrices—particularly useful in probabilistic modeling and kernel methods—without requiring you to hand-code specialized linear algebra routines. Operations like `torch.linalg.solve(A, b)` work transparently on LinearOperator objects, dispatching to the best available algorithm based on the matrix's declared structure.

Use it for:

  • Sampling from high-dimensional multivariate Gaussians with structured covariance matrices without materializing the full matrix.
  • Solving linear systems with low-rank-plus-diagonal structure efficiently via the Woodbury formula.
  • Kernel matrix operations in Gaussian process inference where the kernel matrix is too large to fit in memory.
  • Composing multiple structured matrix types and automatically leveraging efficient algorithms for the resulting composite structure.
  • Prototyping different structured matrix approximations for a model without rewriting linear algebra code for each variant.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

LinearOperator abstracts structured matrix operations in PyTorch, enabling efficient computation on large matrices without materializing them in memory by exploiting their algebraic structure.

Yes, if you work with large structured matrices in PyTorch and need memory efficiency or computational speed. The low install friction and active maintenance support adoption. However, the pre-alpha status and incomplete feature set (symmetric, generic square, rectangular, and sparse operators not yet implemented) mean you should verify that positive semi-definite and triangular operators cover your use case and accept that the API may change.

Install

linear-operator on PyPI

pip

pip install linear-operator

uv

uv add linear-operator

poetry

poetry add linear-operator

Installing linear-operator

Before you install

Low friction install with only torch and scipy as runtime dependencies. Active maintenance with recent releases; currently in pre-alpha (Development Status :: 2 - Pre-Alpha), so expect API changes and incomplete feature coverage.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal obligations—suitable for both open and proprietary projects.

Quickstart

pip install linear_operator

from linear_operator.operators import DiagLinearOperator, LowRankRootLinearOperator
import torch

C = torch.randn(1000, 20)
d = torch.randn(1000)
b = torch.randn(1000)
A = LowRankRootLinearOperator(C) + DiagLinearOperator(d)
result = torch.linalg.solve(A, b)

Requires Python >= 3.10 and torch installed.

Verify before relying

  • Whether positive semi-definite and triangular operators cover your specific matrix structure needs, given the package's stated beta limitations
  • Performance gains on your hardware and matrix sizes relative to dense PyTorch operations
  • Stability of the API given pre-alpha status and the incomplete roadmap (symmetric, generic square, rectangular, and sparse operators still pending)

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — torch, scipy
Maintenance actively maintained — 168 days since the last release
Last repo commit
First released
Downloads 1,139,454/month — #4,309 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: linear_operator-0.6.1-py3-none-any.whl

Development Status :: 2 - Pre-AlphaProgramming Language :: Python :: 3

Tags

structured matrix operations pytorchefficient linear algebra pytorchlow-rank matrix computationkernel matrix operationsmatrix-free linear algebradiagonal plus low-rank solve
matrix-free-computationkernel-methodsgaussian-processes

More Mathematics packages