Skip to content

brahmap.base.InverseLO

Bases: LinearOperator

Construct the inverse operator of a matrix A, as a linear operator.

Parameters:

Name Type Description Default
A _type_

description

required
method _type_

description, by default None

None
preconditioner _type_

description, by default None

None
Source code in brahmap/base/linop.py
class InverseLO(LinearOperator):
    r"""
    Construct the inverse operator of a matrix `A`, as a linear operator.

    Parameters
    ----------
    A : _type_
        _description_
    method : _type_, optional
        _description_, by default None
    preconditioner : _type_, optional
        _description_, by default None

    """

    def __init__(self, A, method=None, preconditioner=None):
        super(InverseLO, self).__init__(
            nargin=A.shape[0], nargout=A.shape[1], matvec=self.mult, symmetric=True
        )
        self.A = A
        self.__method = method
        self.__preconditioner = preconditioner
        self.__converged = None

    def mult(self, x):
        r"""
        It returns  :math:`y=A^{-1}x` by solving the linear system :math:`Ay=x`
        with a certain :mod:`scipy` routine (e.g. :func:`scipy.sparse.linalg.cg`)
        defined above as ``method``.
        """

        y, info = self.method(self.A, x, M=self.preconditioner)
        self.isconverged(info)
        return y

    def isconverged(self, info):
        r"""
        It returns a Boolean value  depending on the
        exit status of the solver.

        **Parameters**

        - ``info`` : {int}
            output of the solver method (usually :func:`scipy.sparse.cg`).
        """
        self.__converged = info
        if info == 0:
            return True
        else:
            return False

    @property
    def method(self):
        r"""
        The method to compute the inverse of A. \
        It can be any :mod:`scipy.sparse.linalg` solver, namely :func:`scipy.sparse.linalg.cg`,
        :func:`scipy.sparse.linalg.bicg`, etc.

        """
        return self.__method

    @property
    def converged(self):
        r"""
        provides convergence information:

        - 0 : successful exit;
        - >0 : convergence to tolerance not achieved, number of iterations;
        - <0 : illegal input or breakdown.

        """
        return self.__converged

    @property
    def preconditioner(self):
        """
        Preconditioner for the solver.
        """
        return self.__preconditioner

converged property

provides convergence information:

  • 0 : successful exit;
  • 0 : convergence to tolerance not achieved, number of iterations;

  • <0 : illegal input or breakdown.

method property

The method to compute the inverse of A. \ It can be any :mod:scipy.sparse.linalg solver, namely :func:scipy.sparse.linalg.cg, :func:scipy.sparse.linalg.bicg, etc.

preconditioner property

Preconditioner for the solver.

isconverged(info)

It returns a Boolean value depending on the exit status of the solver.

Parameters

  • info : {int} output of the solver method (usually :func:scipy.sparse.cg).
Source code in brahmap/base/linop.py
def isconverged(self, info):
    r"""
    It returns a Boolean value  depending on the
    exit status of the solver.

    **Parameters**

    - ``info`` : {int}
        output of the solver method (usually :func:`scipy.sparse.cg`).
    """
    self.__converged = info
    if info == 0:
        return True
    else:
        return False

mult(x)

It returns :math:y=A^{-1}x by solving the linear system :math:Ay=x with a certain :mod:scipy routine (e.g. :func:scipy.sparse.linalg.cg) defined above as method.

Source code in brahmap/base/linop.py
def mult(self, x):
    r"""
    It returns  :math:`y=A^{-1}x` by solving the linear system :math:`Ay=x`
    with a certain :mod:`scipy` routine (e.g. :func:`scipy.sparse.linalg.cg`)
    defined above as ``method``.
    """

    y, info = self.method(self.A, x, M=self.preconditioner)
    self.isconverged(info)
    return y