Composition/Decoration LinearOperators


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 a DiagLinearOperator.

  • linear_ops ((~linear_operator.operators._linear_operator.LinearOperator, ~linear_operator.operators.diag_linear_operator.DiagLinearOperator) or (~linear_operator.operators.diag_linear_operator.DiagLinearOperator, ~linear_operator.operators._linear_operator.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).


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.

  • 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 on output_device


Create a new CatLinearOperator with all LinearOperators in CatLinearOperator moved to one device device. The new CatLinearOperator also has device_id as the output_device.

to(*args, **kwargs)[source]

Returns a new CatLinearOperator with device as the output_device and dtype as the dtype. Warning: this does not move the LinearOperators in this CatLinearOperator to device.

Return type:

~linear_operator.operators._linear_operator.LinearOperator (… x M x N)


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 `


To element-wise multiply two lazy tensors, see linear_operator.operators.MulLinearOperator


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


>>> 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 ]]]


class linear_operator.operators.InterpolatedLinearOperator(base_linear_op, left_interp_indices=None, left_interp_values=None, right_interp_indices=None, right_interp_values=None)[source]


class linear_operator.operators.KroneckerProductLinearOperator(*linear_ops)[source]

Given linearOperators \(\boldsymbol K_1, \ldots, \boldsymbol K_P\), this LinearOperator represents the Kronecker product \(\boldsymbol K_1 \otimes \ldots \otimes \boldsymbol K_P\).


linear_ops (torch.Tensor (… x #M x #N) or ~linear_operator.operators._linear_operator.LinearOperator (… x #M x #N)) – \(\boldsymbol K_1, \ldots, \boldsymbol K_P\): the LinearOperators in the Kronecker product.


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.


linear_ops ((~linear_operator.operators.diag_linear_operator.DiagLinearOperator, …)) – Diagonal linear operators (\(\mathbf D_1, \mathbf D_2, \ldots \mathbf D_\ell\)).


Returns a DiagLinearOperator with the absolute value of all diagonal entries.

Return type:



Returns the inverse of the DiagLinearOperator.

Return type:

~linear_operator.operators._linear_operator.LinearOperator (… x N x N)


Returns a DiagLinearOperator with the square root of all diagonal entries.

Return type:

~linear_operator.operators._linear_operator.LinearOperator (… x M x N)


class linear_operator.operators.MaskedLinearOperator(base, row_mask, col_mask)[source]

A LinearOperator that applies a mask to the rows and columns of a base LinearOperator.


class linear_operator.operators.MatmulLinearOperator(left_linear_op, right_linear_op)[source]


class linear_operator.operators.MulLinearOperator(left_linear_op, right_linear_op)[source]

Returns the Tensors that are used to define the LinearOperator

Return type:

(torch.Tensor, …)


class linear_operator.operators.PsdSumLinearOperator(*linear_ops, **kwargs)[source]

A SumLinearOperator, but where every component of the sum is positive semi-definite


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).

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.