Composition/Decoration LinearOperators
AddedDiagLinearOperator
- class linear_operator.operators.AddedDiagLinearOperator(*linear_ops, preconditioner_override=None)[source]
A
SumLinearOperator
, but of only two linear operators, the second of which must be aDiagLinearOperator
.- Parameters:
linear_ops ((LinearOperator, DiagLinearOperator) or (DiagLinearOperator, LinearOperator)) – The LinearOperator, and the DiagLinearOperator to add to it.
preconditioner_override (Callable, optional) – A preconditioning method to be used with conjugate gradients. If not provided, the default preconditioner (based on the partial pivoted Cholesky factorization) will be used (see Gardner et al., NeurIPS 2018 for details).
CatLinearOperator
- class linear_operator.operators.CatLinearOperator(*linear_ops, dim=0, output_device=None)[source]
A LinearOperator that represents the concatenation of other linear operators. Each LinearOperator must have the same shape except in the concatenating dimension.
- Args:
linear_ops
(list of LinearOperators):A list of LinearOperators whose sizes are the same except in concatenating dimension
dim
dim
(int):The concatenating dimension which can be a batch dimension.
output_device
(torch.device):The CatLinearOperator will appear to appear on
output_device
and place any output torch.Tensors onoutput_device
ConstantMulLinearOperator
- class linear_operator.operators.ConstantMulLinearOperator(base_linear_op, constant)[source]
A LinearOperator that multiplies a base LinearOperator by a scalar constant:
` constant_mul_linear_op = constant * base_linear_op `
Note
To element-wise multiply two lazy tensors, see
linear_operator.operators.MulLinearOperator
- Args:
base_linear_op (LinearOperator) or (b x n x m)): The base_lazy tensor constant (Tensor): The constant
If base_linear_op represents a matrix (non-batch), then constant must be a 0D tensor, or a 1D tensor with one element.
If base_linear_op represents a batch of matrices (b x m x n), then constant can be either: - A 0D tensor - the same constant is applied to all matrices in the batch - A 1D tensor with one element - the same constant is applied to all matrices - A 1D tensor with b elements - a different constant is applied to each matrix
Example:
>>> base_base_linear_op = linear_operator.operators.ToeplitzLinearOperator([1, 2, 3]) >>> constant = torch.tensor(1.2) >>> new_base_linear_op = linear_operator.operators.ConstantMulLinearOperator(base_base_linear_op, constant) >>> new_base_linear_op.to_dense() >>> # Returns: >>> # [[ 1.2, 2.4, 3.6 ] >>> # [ 2.4, 1.2, 2.4 ] >>> # [ 3.6, 2.4, 1.2 ]] >>> >>> base_base_linear_op = linear_operator.operators.ToeplitzLinearOperator([[1, 2, 3], [2, 3, 4]]) >>> constant = torch.tensor([1.2, 0.5]) >>> new_base_linear_op = linear_operator.operators.ConstantMulLinearOperator(base_base_linear_op, constant) >>> new_base_linear_op.to_dense() >>> # Returns: >>> # [[[ 1.2, 2.4, 3.6 ] >>> # [ 2.4, 1.2, 2.4 ] >>> # [ 3.6, 2.4, 1.2 ]] >>> # [[ 1, 1.5, 2 ] >>> # [ 1.5, 1, 1.5 ] >>> # [ 2, 1.5, 1 ]]]
InterpolatedLinearOperator
KroneckerProductLinearOperator
KroneckerProductDiagLinearOperator
- class linear_operator.operators.KroneckerProductDiagLinearOperator(*linear_ops)[source]
Represents the kronecker product of multiple DiagonalLinearOperators (i.e. \(\mathbf D_1 \otimes \mathbf D_2 \otimes \ldots \mathbf D_\ell\)) Supports arbitrary batch sizes.
- Parameters:
linear_ops ((DiagLinearOperator, ...)) – Diagonal linear operators (\(\mathbf D_1, \mathbf D_2, \ldots \mathbf D_\ell\)).
- abs()[source]
Returns a DiagLinearOperator with the absolute value of all diagonal entries.
- Return type:
MatmulLinearOperator
MulLinearOperator
PsdSumLinearOperator
SumBatchLinearOperator
- class linear_operator.operators.SumBatchLinearOperator(base_linear_op, block_dim=-3)[source]
Represents a lazy tensor that is actually the sum of several lazy tensors blocks. The
block_dim
attribute specifies which dimension of the base LinearOperator specifies the blocks. For example, (with block_dim=-3 a k x n x n tensor represents k n x n blocks (a n x n matrix). A b x k x n x n tensor represents k b x n x n blocks (a b x n x n batch matrix).- Args:
base_linear_op
(LinearOperator):A k x n x n LinearOperator, or a b x k x n x n LinearOperator.
block_dim
(int):The dimension that specifies the blocks.