pylops.BlockDiag¶
- class pylops.BlockDiag(ops, nproc=1, forceflat=None, inoutengine=None, parallel_kind='multiproc', dtype=None)[source]¶
Block-diagonal operator.
Create a block-diagonal operator from N linear operators.
- Parameters:
- ops
list Linear operators to be stacked. Alternatively,
numpy.ndarrayorscipy.sparsematrices can be passed in place of one or more operators.- nproc
int, optional Number of processes/threads used to evaluate the N operators in parallel using
multiprocessing/concurrent.futures. Ifnproc=1, work in serial mode.- forceflat
bool, optional Added in version 2.2.0.
Force an array to be flattened after matvec and rmatvec.
- inoutengine
tuple, optional Added in version 2.4.0.
Type of output vectors of matvec and rmatvec. If ``None`, this is inferred directly from the input vectors. Note that this is ignored if
nproc>1.- parallel_kind
str, optional Added in version 2.6.0.
Parallelism kind when
nproc>1. Can bemultiproc(usingmultiprocessing) ormultithread(usingconcurrent.futures.ThreadPoolExecutor). Defaults tomultiproc.- dtype
str, optional Type of elements in input array.
- ops
- Attributes:
- nops
int Number of rows of the full operator (sum of rows of each block).
- mops
int Number of columns of the full operator (sum of columns of each block).
- nnops
numpy.ndarray Cumulative sum of rows of each block, with a leading zero.
- mmops
numpy.ndarray Cumulative sum of columns of each block, with a leading zero.
- dims
tuple Shape of the array after the adjoint, but before flattening.
For example,
x_reshaped = (Op.H * y.ravel()).reshape(Op.dims).- dimsd
tuple Shape of the array after the forward, but before flattening.
For example,
y_reshaped = (Op * x.ravel()).reshape(Op.dimsd).- pool
multiprocessing.Poolorconcurrent.futures.ThreadPoolExecutororNone Pool of workers used to evaluate the N operators in parallel. When
nproc=1, no pool is created (i.e.,pool=None).- shape
tuple Operator shape.
- nops
Notes
A block-diagonal operator composed of N linear operators is created such as its application in forward mode leads to
\[\begin{split}\begin{bmatrix} \mathbf{L}_1 & \mathbf{0} & \ldots & \mathbf{0} \\ \mathbf{0} & \mathbf{L}_2 & \ldots & \mathbf{0} \\ \vdots & \vdots & \ddots & \vdots \\ \mathbf{0} & \mathbf{0} & \ldots & \mathbf{L}_N \end{bmatrix} \begin{bmatrix} \mathbf{x}_{1} \\ \mathbf{x}_{2} \\ \vdots \\ \mathbf{x}_{N} \end{bmatrix} = \begin{bmatrix} \mathbf{L}_1 \mathbf{x}_{1} \\ \mathbf{L}_2 \mathbf{x}_{2} \\ \vdots \\ \mathbf{L}_N \mathbf{x}_{N} \end{bmatrix}\end{split}\]while its application in adjoint mode leads to
\[\begin{split}\begin{bmatrix} \mathbf{L}_1^H & \mathbf{0} & \ldots & \mathbf{0} \\ \mathbf{0} & \mathbf{L}_2^H & \ldots & \mathbf{0} \\ \vdots & \vdots & \ddots & \vdots \\ \mathbf{0} & \mathbf{0} & \ldots & \mathbf{L}_N^H \end{bmatrix} \begin{bmatrix} \mathbf{y}_{1} \\ \mathbf{y}_{2} \\ \vdots \\ \mathbf{y}_{N} \end{bmatrix} = \begin{bmatrix} \mathbf{L}_1^H \mathbf{y}_{1} \\ \mathbf{L}_2^H \mathbf{y}_{2} \\ \vdots \\ \mathbf{L}_N^H \mathbf{y}_{N} \end{bmatrix}\end{split}\]Methods
__init__(ops[, nproc, forceflat, ...])adjoint()apply_columns(cols)Apply subset of columns of operator
close()Close the pool of workers used for multiprocessing / multithreading.
cond([uselobpcg])Condition number of linear operator.
conj()Complex conjugate operator
div(y[, niter, densesolver])Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\).
dot(x)Matrix-matrix or matrix-vector multiplication.
eigs([neigs, symmetric, niter, uselobpcg])Most significant eigenvalues of linear operator.
matmat(X)Matrix-matrix multiplication.
matvec(x)Matrix-vector multiplication.
reset_count()Reset counters
rmatmat(X)Matrix-matrix multiplication.
rmatvec(x)Adjoint matrix-vector multiplication.
todense([backend])Return dense matrix.
toimag([forw, adj])Imag operator
toreal([forw, adj])Real operator
tosparse()Return sparse matrix.
trace([neval, method, backend])Trace of linear operator.
transpose()
Examples using pylops.BlockDiag¶
PWD-based slope estimation and structural smoothing