Blocks

In practice, LinearOperator instances composed of distinct sub-blocks are common. In general, access to both the constituent operators and larger operators is desired. The block module provides several functions to help build block instances of LinearOperator from simpler components.

hstack() and vstack() are the workhorses of block and are analogous to their numpy counterparts. These functions can be used alone to squash a row or column of LinearOperator instances, respectively, into a single LinearOperator instance. These functions expect a list of LinearOperator instances as input.

bmat() is the generic block-builder, and takes in a list of lists of LinearOperator instances and returns a single block operator. bmat() assumes the list of lists is in row-major order.

blockDiag() allows for easy creation of common block diagonal operators, given a list of the diagonal component operators.

\[\begin{split}E = \begin{bmatrix} A & B \\ C & D \end{bmatrix}\end{split}\]

We can easily build \(E\) or just its rows and columns using block functions.

A = LinearOperator((10, 12), forward, adjoint)
B = LinearOperator((10, 30), forward, adjoint)
C = LinearOperator((15, 12), forward, adjoint)
D = LinearOperator((15, 30), forward, adjoint)

row1 = hstack([A, B])
row2 = hstack([C, D])

col1 = vstack([A, C])
col2 = vstack([B, D])

E1 = vstack([row1, row2])
E2 = hstack([col1, col2])
E3 = bmat([[A, B], [C, D]])

In this example, E1, E2, and E3 are equivalent.

We can also easily make block diagonal operators with blockDiag():

\[\begin{split}D = \begin{bmatrix} A & \mathbf{0} & \mathbf{0} \\ \mathbf{0} & B & \mathbf{0} \\ \mathbf{0} & \mathbf{0} & C \end{bmatrix}\end{split}\]
A = LinearOperator(op_shape1, forward1, adjoint1)
B = LinearOperator(op_shape2, forward2, adjoint2)
C = LinearOperator(op_shape3, forward3, adjoint3)

D = blockDiag([A, B, C])
blockDiag(blocks)[source]

Converts a list of operators into a new operator.

The new operator is composed of diagonal blocks described by the list.

Parameters:

blocks : [LinearOperator]

A list of LinearOperator objects.

Returns:

LinearOperator

The new block operator.

See also

bmat
Construct a LinearOperator from LinearOperator subcomponents.

Examples

>>> from pyop.block import blockDiag
>>> from pyop import toLinearOperator, toMatrix
>>> from numpy import array
>>> A = toLinearOperator(array([[1., 2.], [3., 4.]]))
>>> B = toLinearOperator(array([[5., 6.], [7., 8.]]))
>>> C = blockDiag([A, B])
>>> toMatrix(C)
array([[ 1.,  2.,  0.,  0.],
       [ 3.,  4.,  0.,  0.],
       [ 0.,  0.,  5.,  6.],
       [ 0.,  0.,  7.,  8.]])
bmat(blocks)[source]

Converts a list of lists into a new operator.

The new operator is composed of blocks described by the list.

Parameters:

blocks : [[LinearOperator]]

A list of lists, with each base component a linear operator (objects instantiated from the LinearOperator class).

Returns:

LinearOperator

The new block operator.

See also

blockDiag
Construct a LinearOperator from block diagonal components.
hstack
Squash a row of LinearOperators to a single block LinearOperator.
vstack
Squash a column of LinearOperators to a single block LinearOperator.

Examples

>>> from pyop import toLinearOperator, toMatrix
>>> from pyop.block import bmat
>>> from numpy import array
>>> A = toLinearOperator(array([[1., 2.], [0., 4.]]))
>>> B = toLinearOperator(array([[3., 0.], [5., 0.]]))
>>> C = toLinearOperator(array([[6., 0., 0., 7], [0., 8., 9., 0.]]))
>>> blocks = [[A, B], [C]]
>>> D = bmat(blocks)
>>> toMatrix(D)
array([[ 1.,  2.,  3.,  0.],
       [ 0.,  4.,  5.,  0.],
       [ 6.,  0.,  0.,  7.],
       [ 0.,  8.,  9.,  0.]])
hstack(blocks)[source]

Converts list of operators into one operator.

The new operator is created assuming the list corresponds to a row of blocks in a larger block matrix-like operator.

Parameters:

blocks : [LinearOperator]

A list of LinearOperator objects.

Returns:

LinearOperator

The new block operator.

See also

vstack
Squash a column of LinearOperators to a single block LinearOperator.
bmat
Construct a LinearOperator from LinearOperator subcomponents.

Examples

>>> from pyop.block import hstack
>>> from pyop import toLinearOperator, toMatrix
>>> from numpy import array
>>> A = toLinearOperator(array([[1., 2.], [4., 5.]]))
>>> B = toLinearOperator(array([[3.], [6.]]))
>>> C = hstack([A, B])
>>> toMatrix(C)
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])
vstack(blocks)[source]

Converts list of operators into one operator.

The new operator is created assuming the list corresponds to a column of blocks in a larger block matrix-like operator.

Parameters:

blocks : [LinearOperator]

A list of LinearOperator objects.

Returns:

LinearOperator

The new block operator.

See also

hstack
Squash a row of LinearOperators to a single block LinearOperator.
bmat
Construct a LinearOperator from LinearOperator subcomponents.

Examples

>>> from pyop.block import vstack
>>> from pyop import toLinearOperator, toMatrix
>>> from numpy import array
>>> A = toLinearOperator(array([[1., 4.], [2., 5.]]))
>>> B = toLinearOperator(array([[3., 6.]]))
>>> C = vstack([A, B])
>>> toMatrix(C)
array([[ 1.,  4.],
       [ 2.,  5.],
       [ 3.,  6.]])

Matrix Free Linear Operators

Navigation