mrpro.operators.LinearOperatorMatrix
- class mrpro.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
LinearOperator
and Tensors.- __init__(operators: Sequence[Sequence[LinearOperator]])[source]
Initialize Linear Operator Matrix.
Create a matrix of
LinearOperator
from a sequence of rows, where each row is a sequence ofLinearOperator
that 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
LinearOperatorMatrix
with the given linear operators on the diagonal, resulting in a block-diagonal linear operator.- Parameters:
operators (
LinearOperator
) – Sequence ofLinearOperator
to 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 bounds \(||[A, B]^T||\leq\sqrt{(||A||^2 + ||B||^2)}\) and \(||[A, B]||\leq\max(||A||,||B||)\) to estimate the operator norm of the matrix. First, operator_norm is called on each element of the matrix. Next, the norm is estimated for each column using the first bound. Finally, the norm of the full matrix of linear operators is calculated using the second bound.
- 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.
- __and__(other: LinearOperator | LinearOperatorMatrix) Self [source]
Horizontal stacking.
- __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]
Vertical stacking.
- __rand__(other: LinearOperator) 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]
Vertical stacking.