Skip to content

brahmap.base.DiagonalOperator

Bases: LinearOperator

A linear operator for a diagonal matrix

Parameters:

Name Type Description Default
diag ndarray

description

required
**kwargs Any

description

{}
Source code in brahmap/base/linop.py
class DiagonalOperator(LinearOperator):
    """A linear operator for a diagonal matrix

    Parameters
    ----------
    diag : np.ndarray
        _description_
    **kwargs: Any
        _description_
    """

    def __init__(self, diag: np.ndarray, **kwargs: Any):
        if "symmetric" in kwargs:
            kwargs.pop("symmetric")
        if "matvec" in kwargs:
            kwargs.pop("matvec")
        if "dtype" in kwargs:
            kwargs.pop("dtype")

        self.diag = np.asarray(diag)
        if self.diag.ndim != 1:
            msg = "diag array must be 1-d"
            raise ValueError(msg)

        super(DiagonalOperator, self).__init__(
            self.diag.shape[0],
            self.diag.shape[0],
            symmetric=True,
            matvec=lambda x: self.diag * x,
            dtype=self.diag.dtype,
            **kwargs,
        )