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


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.


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]

Returns the Kronecker product of the given lazy tensors


List of lazy tensors


Adds a diagonal to a KroneckerProductLinearOperator


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



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

Return type



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


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.