mr2.operators.LinearOperatorMatrix
- class mr2.operators.LinearOperatorMatrix[source]
Bases:
Operator[Unpack[tuple[Tensor, …]],tuple[Tensor, …]]Matrix of linear operators.
A matrix of linear operators, where each element is a
LinearOperator.This matrix can be applied to a sequence of tensors, where the number of tensors should match the number of columns of the matrix. The output will be a sequence of tensors, where the number of tensors will match the number of rows of the matrix. The i-th output tensor is calculated as \(\sum_j \text{operators}[i][j](x[j])\) where \(\text{operators}[i][j]\) is the linear operator in the i-th row and j-th column and \(x[j]\) is the j-th input tensor.
The matrix can be indexed and sliced like a regular matrix to get submatrices. If indexing returns a single element, it is returned as a
LinearOperator.Basic arithmetic operations are supported with
LinearOperatorand Tensors. UseA | Bfor horizontal stacking (side-by-side columns) andA % Bfor vertical stacking (stacked rows).- __init__(operators: Sequence[Sequence[LinearOperator]])[source]
Initialize Linear Operator Matrix.
Create a matrix of
LinearOperatorfrom a sequence of rows, where each row is a sequence ofLinearOperatorthat represent the columns of the matrix.- Parameters:
operators (
Sequence[Sequence[LinearOperator]]) – A sequence of rows, which are sequences ofLinearOperator.
- classmethod from_diagonal(*operators: LinearOperator) Self[source]
Create a diagonal
LinearOperatorMatrix.Construct a square
LinearOperatorMatrixwith the given linear operators on the diagonal, resulting in a block-diagonal linear operator.- Parameters:
operators (
LinearOperator) – Sequence ofLinearOperatorto be placed on the diagonal.
- __call__(*x: Tensor) tuple[Tensor, ...][source]
Apply the linear operator matrix to a sequence of input tensors.
The i-th output tensor is calculated as the sum over j of
operators[i][j](x[j]), whereoperators[i][j]is the linear operator in the i-th row and j-th column, andx[j]is the j-th input tensor.- Parameters:
*x (
Tensor) – Input tensors. The number of input tensors must match the number of columns in the operator matrix.- Returns:
Output tensors. The number of output tensors will match the number of rows in the operator matrix.
- adjoint(*x: Tensor) tuple[Tensor, ...][source]
Apply the adjoint of the linear operator matrix.
This is achieved by applying the matrix composed of the adjoints of each individual operator (i.e.,
self.H) to the input tensors*x. The k-th output tensor issum_i self.operators[i][k].H(x[i]).- Parameters:
*x (
Tensor) – Input tensors. The number of input tensors must match the number of rows in the original operator matrix.- Returns:
Output tensors. The number of output tensors will match the number of columns in the original operator matrix.
- forward(*x: Tensor) tuple[Tensor, ...][source]
Apply forward of LinearOperatorMatrix.
Note
Prefer calling the instance of the LinearOperatorMatrix operator as
operator(x)over directly calling this method. See this PyTorch discussion.
- operator_norm(*initial_value: Tensor, dim: Sequence[int] | None = None, max_iterations: int = 20, relative_tolerance: float = 1e-4, absolute_tolerance: float = 1e-5, callback: Callable[[Tensor], None] | None = None) Tensor[source]
Upper bound of operator norm of the Matrix.
Uses the operator norm of the matrix of entrywise operator norms to estimate the norm of the block operator induced by the product \(\ell_2\) norm on tuples. First,
operator_normis called on each element of the matrix. The resulting matrix of scalar bounds is then combined with the spectral matrix norm.- Parameters:
initial_value (
Tensor) – Initial value(s) for the power iteration, length should match the number of columns of the operator matrix.dim (
Sequence[int] |None, default:None) – Dimensions to calculate the operator norm over. Other dimensions are assumed to be batch dimensions. None means all dimensions.max_iterations (
int, default:20) – Maximum number of iterations used in the power iteration.relative_tolerance (
float, default:1e-4) – Relative tolerance for convergence.absolute_tolerance (
float, default:1e-5) – Absolute tolerance for convergence.callback (
Callable[[Tensor],None] |None, default:None) – Callback function to be called with the current estimate of the operator norm.
- Returns:
Estimated operator norm upper bound.
- __matmul__(other: LinearOperator | Self) Self[source]
Composition of operators.
- __mul__(other: Tensor | Sequence[Tensor | complex] | complex) Self[source]
LinearOperatorMatrix*Tensor multiplication.
Example: \(([A,B]c)(x) = [Ac, Bc](x) = A(cx) + B(cx)\)
- __or__(other: LinearOperator | LinearOperatorMatrix) Self[source]
Horizontal stacking.
- __rmatmul__(other: LinearOperator) Self[source]
Composition of operators.
- __rmul__(other: Tensor | Sequence[Tensor] | complex) Self[source]
Tensor*LinearOperatorMatrix multiplication.
Example: (c[A,B])(x) = [cA, cB](x) = cA(x) + cB(x)
- __ror__(other: LinearOperator) Self[source]
Horizontal stacking.