Skip to content

brahmap.base.SymmetricallyReducedLinearOperator

Implements reduction of a linear operator (symmetrical).

Reduces a linear operator symmetrically by reducing boths its input and output to indices.

Source code in brahmap/base/linop.py
def SymmetricallyReducedLinearOperator(op, indices):
    """
    Implements reduction of a linear operator (symmetrical).

    Reduces a linear operator symmetrically by reducing boths its input and
    output to `indices`.

    """

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

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

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

    return LinearOperator(
        nargin, nargin, matvec=matvec, symmetric=op.symmetric, rmatvec=rmatvec
    )