Skip to content

brahmap.base.SymmetricallyReducedLinearOperator

Symmetrically restricts a linear operator to a subset of its dimensions.

This operation is similar to ReducedLinearOperator but it restricts both of the dimensions equally.

Parameters:

Name Type Description Default
op LinearOperator

The original linear operator to be reduced

required
indices Sequence[int]

Indices to restrict both the input and output vectors

required

Returns:

Type Description
LinearOperator

A new symmetrically reduced linear operator of shape (len(indices), len(indices))

Source code in brahmap/base/linop.py
def SymmetricallyReducedLinearOperator(op: LinearOperator, indices):
    """
    Symmetrically restricts a linear operator to a subset of its dimensions.

    This operation is similar to [`ReducedLinearOperator`][..ReducedLinearOperator]
    but it restricts both of the dimensions equally.

    Parameters
    ----------
    op : LinearOperator
        The original linear operator to be reduced
    indices : Sequence[int]
        Indices to restrict both the input and output vectors

    Returns
    -------
    LinearOperator
        A new symmetrically reduced linear operator of shape
        `(len(indices), len(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]  # type: ignore

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

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