https://github.com/cvxgrp/torch_linops
A library to define abstract linear operators, and associated algebra and matrix-free algorithms, that works with pyTorch Tensors.
Science Score: 33.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
✓Committers with academic emails
1 of 2 committers (50.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.4%) to scientific vocabulary
Keywords
Repository
A library to define abstract linear operators, and associated algebra and matrix-free algorithms, that works with pyTorch Tensors.
Basic Info
Statistics
- Stars: 14
- Watchers: 6
- Forks: 1
- Open Issues: 0
- Releases: 5
Topics
Metadata Files
README.md
An Abstract Linear Operator Library for pyTorch
This library implements a generic structure for abstract linear operators and
enables a number of standard operations on them:
* Arithmetic: A + B, A - B, -A, A @ B all work exactly as expected to
combine linear operators.
* Indexing: A[k:ell,m:n] works as expected.
* Solves: Ax = b can be solved with CG for PSD matrices, minres for
symmetric matrices, LSQR (to be implemented), or LSMR (to be implemented).
* Trace estimation: The trace of square matrices, can be estimated via Hutch++
and Hutchinson's estimator.
* Diamond-Boyd stochastic equilibration
* Randomized Nyström Preconditioning
* Automatic adjoint operator generation.
Using LinearOperators
The public API of the LinearOperator library is that every LinearOperator has the
following properties and methods:
```python
class LinearOperator:
# Properties
shape: tuple[int, int]
T: LinearOperator
supports_operator_matrix: bool
device: torch.Device
# Matrix multiply
def __matmul__(self, b: torch.Tensor) -> torch.Tensor: ...
def __rmatmul__(self, b: torch.Tensor) -> torch.Tensor: ...
def __matmul__(self, b: LinearOperator) -> LinearOperator: ...
def __rmatmul__(self, b: LinearOperator) -> LinearOperator: ...
# Linear Solve Methods
def solve_I_p_lambda_AT_A_x_eq_b(self,
lambda_: float,
b: torch.Tensor,
x0: torch.Tensor | None=None,
*, precondition: None | Literal['nsytrom'], hot=False) -> torch.Tensor: ...
def solve_A_x_eq_b(self,
b: torch.Tensor,
x0: torch.Tensor | None=None) -> torch.Tensor: ...
# Transformations on LinearOperator
def __mul__(self, c: float) -> LinearOperator: ...
def __rmul__(self, c: float) -> LinearOperator: ...
def __truediv__(self, c: float) -> LinearOperator: ...
def __pow__(self, k: int) -> LinearOperator: ...
def __add__(self, c: LinearOperator) -> LinearOperator: ...
def __sub__(self, c: LinearOperator) -> LinearOperator: ...
def __neg__(self) -> LinearOperator: ...
def __pos__(self) -> LinearOperator: ...
def __getitem__(self, key) -> LinearOperator: ...
```
The following functions are available in the root of the library: ```python def operatormatrixproduct(A: LinearOperator, M: torch.Tensor) -> torch.Tensor: ... def aslinearoperator(A: torch.Tensor | LinearOperator) -> LinearOperator: ... def vstack(ops: list[LinearOperator] | tuple[LinearOperator, ...]) -> LinearOperator: ... def hstack(ops: list[LinearOperator] | tuple[LinearOperator, ...]) -> LinearOperator: ...
To be implemented:
def bmat(ops: list[list[LinearOperator]]) -> LinearOperator: ... # Optimizes out ZeroOperator ```
The following functions are available in linops.trace for trace estimation:
python
def hutchpp(A: lo.LinearOperator, m: int) -> float: ...
def hutchinson(A: lo.LinearOperator, m: int) -> float: ...
linops.equilibration contains equilibrate and symmetric_equilibrate.
Their public API is not finalized, if you wish to use them it is recommend you read the source code.
Creating Linear Operators
Linear operators can be constructed in the following way:
* Creating a sub-class of LinearOperator
* Calling one of the following constructors:
* IdentityOperator(n: int)
* DiagonalOperator(diag: torch.Tensor): where diag is a 1D torch tensor.
* MatrixOperator(M: torch.Tensor): where M is a 2D torch tensor.
* SelectionOperator(shape: tuple[int, int], idxs: slice | list[int | slice])
* KKTOperator(H: LinearOperator, A: LinearOperator): where H is a square LinearOperator and A is a LinearOperator
* VectorJacobianOperator(f: torch.Tensor, x: torch.Tensor): where f is the output of the function being differentiated
which has a torch autograd value and x is the vector on which ensures_grad was called.
* ZeroOperator(shape: tuple[int, int])
* Combining operators via:
* A + B, A - B, A @ B for A, B linear operators
* hstack, vstack
* A, c A, A / c, v * A, A / v for scalar c and vector v.
Implementing LinearOperators
To implement a LinearOperator the following are mandatory:
- Set
_shape: tuple[int, int]to the shape of the operator. - Set
deviceappropriately, if the operator requires vectors to be on a particular device. - Implement a method
def _matmul_impl(self, v: torch.Tensor) -> torch.Tensor: ...that implements your matrix vector product.
The following are recommended to improve performance:
- If your
_matmul_implmethod handles matrix inputs correctly, setsupports_operator_matrix: booltoTrue. - If it is possible to describe the adjoint operator, set
_adjoint: LinearOperatorto point to the adjoint of your operator. If you do not compute this, then one will be autogenerated by differentiating through your_matmul_impl.
It is suggested that, if possible, you replace any other methods with specialized implementations.
Owner
- Name: Stanford University Convex Optimization Group
- Login: cvxgrp
- Kind: organization
- Location: Stanford, CA
- Website: www.stanford.edu/~boyd
- Repositories: 102
- Profile: https://github.com/cvxgrp
GitHub Events
Total
- Create event: 1
- Issues event: 3
- Release event: 1
- Watch event: 4
- Issue comment event: 1
- Push event: 3
- Pull request review event: 1
- Pull request event: 2
- Fork event: 1
Last Year
- Create event: 1
- Issues event: 3
- Release event: 1
- Watch event: 4
- Issue comment event: 1
- Push event: 3
- Pull request review event: 1
- Pull request event: 2
- Fork event: 1
Committers
Last synced: about 3 years ago
All Time
- Total Commits: 52
- Total Committers: 2
- Avg Commits per committer: 26.0
- Development Distribution Score (DDS): 0.192
Top Committers
| Name | Commits | |
|---|---|---|
| Parth Nobel | p****l@b****u | 42 |
| Thistleman | c****6@g****m | 10 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 9 months ago
All Time
- Total issues: 2
- Total pull requests: 3
- Average time to close issues: 6 days
- Average time to close pull requests: 16 days
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.5
- Average comments per pull request: 0.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 2
- Average time to close issues: 6 days
- Average time to close pull requests: about 2 hours
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 0.5
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- healeyq3 (2)
Pull Request Authors
- healeyq3 (2)
- PTNobel (1)
- Thistleman (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 24 last-month
- Total dependent packages: 1
- Total dependent repositories: 1
- Total versions: 2
- Total maintainers: 1
pypi.org: torch-linops
A library to define abstract linear operators, and associated algebra and matrix-free algorithms, that works with pyTorch Tensors.
- Homepage: https://github.com/cvxgrp/torch_linops
- Documentation: https://torch-linops.readthedocs.io/
- License: GPLv3
-
Latest release: 0.1.3
published about 3 years ago
Rankings
Maintainers (1)
Dependencies
- scipy *
- torch *
- scipy *
- torch *
- actions/checkout v3 composite
- actions/setup-python v3 composite
- conda-incubator/setup-miniconda v2 composite
- actions/checkout v3 composite
- actions/setup-python v3 composite
- conda-incubator/setup-miniconda v2 composite