--- id: linear-operator version: "0.6.1" license: MIT license_treatment: permissive maintenance: active --- # linear-operator — A linear operator implementation, primarily designed for finite-dimensional positive definite operators (i.e. kernel matrices). License: permissive · Maintenance: active · Downloads: 1.1M/mo ## 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 above — 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 pip install linear-operator uv add linear-operator 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_current - Install friction: low - Maintenance: active - Downloads: 1.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags structured matrix operations pytorch, efficient linear algebra pytorch, low-rank matrix computation, kernel matrix operations, matrix-free linear algebra, diagonal plus low-rank solve, matrix-free-computation, kernel-methods, gaussian-processes [View on SkillFed](https://skillfed.io/packages/linear-operator) · [View on PyPI](https://pypi.org/project/linear-operator/)