Registry / ai-ml / linear-operator

linear-operator

JSON →
library0.6.1pypypi✓ verified 22d ago

LinearOperator is a PyTorch package for abstracting away linear algebra routines needed for structured matrices or operators, primarily designed for finite-dimensional positive definite operators (i.e., kernel matrices). It is actively developed, with its current version being 0.6.1, and typically releases maintenance updates and minor versions frequently.

pip install linear_operator
INSTALL
IMPORT
SIG · LINEAR-OPERATOR
L
linear-operator
ai-mlpythonv0.6.1
Install
70.3s avg
Import
6488ms
Disk
4941MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 80s
py 3.11
✕ build_error
✓ 72.8s
py 3.12
✕ build_error
✓ 67.7s
py 3.13
✕ build_error
✓ 60.9s
py 3.9
✕ build_error
✕ timeout
4941MB installed
● package 4941MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LinearOperator
from linear_operator.operators import LinearOperator
This is the base class for all linear operators. Specific operators like DiagLinearOperator, KroneckerProductLinearOperator, etc., are also imported from `linear_operator.operators`.
DiagLinearOperator
from linear_operator.operators import DiagLinearOperator
LowRankRootLinearOperator
from linear_operator.operators import LowRankRootLinearOperator

This example demonstrates how to construct a large-scale structured matrix (a sum of a low-rank matrix and a diagonal matrix) as a `LinearOperator` object. The library implicitly handles the algebraic structure, allowing efficient operations like linear solves using `torch.linalg.solve` without ever forming the full, dense matrix, which is crucial for large-scale problems.

import torch from linear_operator.operators import LowRankRootLinearOperator, DiagLinearOperator # Example: Represent a 10000 x 10000 matrix A = C C^T + D # A is never explicitly instantiated as a dense matrix, saving memory C = torch.randn(10000, 20) # A "skinny" matrix (e.g., 10000x20) d = torch.randn(10000).abs() + 1e-6 # Diagonal elements (ensure positive) b = torch.randn(10000) A = LowRankRootLinearOperator(C) + DiagLinearOperator(d) # Perform a linear solve efficiently without instantiating the full dense matrix # This uses structure-exploiting algorithms like Woodbury formula under the hood x = torch.linalg.solve(A, b) print(f"Shape of A: {A.shape}") print(f"Shape of b: {b.shape}") print(f"Shape of x (solution): {x.shape}")
Debug
Known issues
breakingVersion 0.6 introduced stricter Python and PyTorch version requirements. Python 3.10+ and PyTorch 2.0+ are now mandatory.
fix
Upgrade Python to 3.10 or higher and PyTorch to 2.0 or higher. For PyTorch, ensure you install the correct version for your CUDA toolkit.
affects: >=0.6
gotchaThe internal methods for sparse tensor construction were updated in v0.6.1. Users who have custom `LinearOperator` implementations or interact directly with sparse tensor construction might encounter changes or deprecation warnings.
fix
Review your sparse tensor construction logic and update it to align with PyTorch's current best practices, as the library now uses deprecated sparse tensor construction methods internally.
affects: >=0.6.1
breakingThe initialization arguments for `_dtype_value_context` changed in version 0.4.0. If you have custom `LinearOperator` subclasses that override or interact with this internal context, your code may break.
fix
Adjust the argument passing to `_dtype_value_context` in your custom `LinearOperator` implementations according to the new signature in v0.4.0.
affects: >=0.4.0
gotchaIn version 0.6.1, `BlockDiagLinearOperator` now converts its `base_linear_op` to a dense linear operator. This might lead to increased memory usage or altered performance if you were relying on lazy evaluation of the base operator within `BlockDiagLinearOperator` in previous versions.
fix
Be aware of potential memory and performance impacts when using `BlockDiagLinearOperator` with complex `base_linear_op` instances. Evaluate if this change affects your specific use case.
affects: >=0.6.1
Errors
Common errors & fixes
AttributeError: module 'gpytorch.operators' has no attribute 'DiagLinearOperator'
The `linear_operator` package, containing many linear operators, was split out of `gpytorch` in GPyTorch 1.x. Operators like `DiagLinearOperator` are no longer directly accessible via `gpytorch.operators`.
fix
Update your imports to use `from linear_operator.operators import DiagLinearOperator` instead of `from gpytorch.operators import DiagLinearOperator`. Ensure `linear-operator` is installed (`pip install linear-operator`).
ModuleNotFoundError: No module named 'linear_operator'
The `linear-operator` Python package has not been installed in your current environment, or the environment is not correctly activated.
fix
Install the package using pip: `pip install linear-operator`.
ImportError: cannot import name 'DiagLinearOperator' from 'linear_operator'
You are attempting to import a specific linear operator directly from the top-level `linear_operator` package, but these operators reside in the `linear_operator.operators` submodule.
fix
Change your import statement to `from linear_operator.operators import DiagLinearOperator`.
RuntimeError: inverse_bilinear_form expected square matrix
This error occurs when a `LinearOperator` method that requires a square matrix (like `inverse_bilinear_form`) is called on an operator that is not square.
fix
Ensure the `LinearOperator` object you are performing the operation on represents a square matrix, or verify the dimensions of the input arguments passed to the method are consistent with a square matrix operation.
Upgrade
Version history
0.6.1latest on PyPI · released Feb 27, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or higher.
pytorchrequiredCore dependency for tensor operations and GPU support, requires PyTorch 2.0 or higher.
Agent activity
6 hits · last 30 days
node
4
Amazon
1
Resources