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.
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():
A = LinearOperator(op_shape1, forward1, adjoint1)
B = LinearOperator(op_shape2, forward2, adjoint2)
C = LinearOperator(op_shape3, forward3, adjoint3)
D = blockDiag([A, B, C])
Converts a list of operators into a new operator.
The new operator is composed of diagonal blocks described by the list.
| Parameters: | blocks : [LinearOperator]
|
|---|---|
| Returns: | LinearOperator
|
See also
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.]])
Converts a list of lists into a new operator.
The new operator is composed of blocks described by the list.
| Parameters: | blocks : [[LinearOperator]]
|
|---|---|
| Returns: | LinearOperator
|
See also
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.]])
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]
|
|---|---|
| Returns: | LinearOperator
|
See also
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.]])
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]
|
|---|---|
| Returns: | LinearOperator
|
See also
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.]])