Skip to content

brahmap.base.ReducedLinearOperator

Implements reduction of a linear operator (non symmetrical).

Reduces a linear operator by limiting its input to col_indices and its output to row_indices.

Source code in brahmap/base/linop.py
def ReducedLinearOperator(op, row_indices, col_indices):
    """
    Implements reduction of a linear operator (non symmetrical).

    Reduces a linear operator by limiting its input to `col_indices` and its
    output to `row_indices`.

    """

    nargin, nargout = len(col_indices), len(row_indices)
    m, n = op.shape  # Shape of non-reduced operator.

    def matvec(x):
        z = np.zeros(n, dtype=x.dtype)
        z[col_indices] = x[:]
        y = op * z
        return y[row_indices]

    def rmatvec(x):
        z = np.zeros(m, dtype=x.dtype)
        z[row_indices] = x[:]
        y = op.H * z
        return y[col_indices]

    return LinearOperator(
        nargin, nargout, matvec=matvec, symmetric=False, rmatvec=rmatvec
    )