コード例 #1
0
ファイル: pyma57.py プロジェクト: vishalbelsare/nlpy
    def __init__( self, A, factorize=True, **kwargs ):
        """
        Create a PyMa57Context object representing a context to solve
        the square symmetric linear system of equations

            A x = b.

        A should be given in ll_mat format and should be symmetric.
        The system will first be analyzed and factorized, for later
        solution. Residuals will be computed dynamically if requested.

        The factorization is a multi-frontal variant of the Bunch-Parlett
        factorization, i.e.

            A = L B Lt

        where L is unit lower triangular, and B is symmetric and block diagonal
        with either 1x1 or 2x2 blocks.

        A special option is available is the matrix A is known to be symmetric
        (positive or negative) definite, or symmetric quasi-definite (sqd).
        SQD matrices have the general form

            [ E  Gt ]
            [ G  -F ]

        where both E and F are positive definite. As a special case, positive
        definite matrices and negative definite matrices are sqd. SQD matrices
        can be factorized with potentially much sparser factors. Moreover, the
        matrix B reduces to a diagonal matrix.

        Currently accepted keyword arguments are:

           sqd  Flag indicating symmetric quasi-definite matrix (default: False)

        Example:

        >>> import pyma57
        >>> import numpy
        >>> P = pyma57.PyMa57Context(A)
        >>> P.solve(rhs, get_resid=True)
        >>> print numpy.linalg.norm(P.residual)

        Pyma57 relies on the sparse direct multifrontal code MA57
        from the Harwell Subroutine Library.

        From the MA57 spec sheet, 'In addition to being more efficient largely
        through its use of the Level 3 BLAS, it has many added features. Among
        these are: a fast mapping of data prior to a numerical factorization,
        the ability to modify pivots if the matrix is not definite, the
        efficient solution of several right-hand sides, a routine implementing
        iterative refinement, and the possibility of restarting the
        factorization should it run out of space.'


        References
        ----------

        1. I. S. Duff, "MA57 -- A New Code for the Solution of Sparse Symmetric
           Indefinite Systems", ACM Transactions on Mathematical Software (30),
           p. 118-144, 2004.
        2. I. S. Duff and J. K. Reid, "The Multifrontal Solution of Indefinite
           Sparse Symmetric Linear Systems", Transactions on Mathematical
           Software (9), p. 302--325, 1983.
        3. http://hsl.rl.ac.uk/hsl2007/hsl20074researchers.html
        """

        if isinstance(A, PysparseMatrix):
            thisA = A.matrix
        else:
            thisA = A

        Sils.__init__( self, thisA, **kwargs )

        # Statistics on A
        self.nzFact = 0      # Number of nonzeros in factors
        self.nRealFact = 0   # Storage for real data of factors
        self.nIntFact = 0    # Storage for int  data of factors
        self.front = 0       # Largest front size
        self.n2x2pivots = 0  # Number of 2x2 pivots used
        self.neig = 0        # Number of negative eigenvalues detected
        self.rank = 0        # Matrix rank

        # Factors
        #self.L = spmatrix.ll_mat( self.n, self.n, 0 )
        #self.B = spmatrix.ll_mat_sym( self.n, 0 )

        # Analyze and factorize matrix
        self.context = _pyma57.analyze( thisA, self.sqd )
        self.factorized = False
        if factorize: self.factorize(thisA)
        return
コード例 #2
0
ファイル: pyma27.py プロジェクト: b45ch1/nlpy
    def __init__( self, A, **kwargs ):
        """
        Create a PyMa27Context object representing a context to solve
        the square symmetric linear system of equations

            A x = b.
    
        A should be given in ll_mat format and should be symmetric.
        The system will first be analyzed and factorized, for later
        solution. Residuals will be computed dynamically if requested.

        The factorization is a multi-frontal variant of the Bunch-Parlett
        factorization, i.e.

            A = L B Lt

        where L is unit lower triangular, and B is symmetric and block diagonal
        with either 1x1 or 2x2 blocks.
        
        A special option is available is the matrix A is known to be symmetric
        (positive or negative) definite, or symmetric quasi-definite (sqd).
        SQD matrices have the general form

            [ E  Gt ]
            [ G  -F ]

        where both E and F are positive definite. As a special case, positive
        definite matrices and negative definite matrices are sqd. SQD matrices
        can be factorized with potentially much sparser factors. Moreover, the
        matrix B reduces to a diagonal matrix.

        Currently accepted keyword arguments are:

           sqd  Flag indicating symmetric quasi-definite matrix (default: False)

        Example:
            from nlpy.linalg import pyma27
            from nlpy.tools import norms
            P = pyma27.PyMa27Context( A )
            P.solve( rhs, get_resid = True )
            print norms.norm2( P.residual )

        Pyma27 relies on the sparse direct multifrontal code MA27
        from the Harwell Subroutine Library archive.
        """

        if isinstance(A, PysparseMatrix):
            thisA = A.matrix
        else:
            thisA = A

        Sils.__init__( self, thisA, **kwargs )

        # Statistics on A
        self.rwords = 0      # Number of real words used during factorization
        self.iwords = 0      #           int
        self.ncomp  = 0      #           data compresses performed in analysis
        self.nrcomp = 0      #           real
        self.nicomp = 0      #           int
        self.n2x2pivots = 0  #           2x2 pivots used
        self.neig   = 0      #           negative eigenvalues detected

        # Factors
        self.L = spmatrix.ll_mat( self.n, self.n, 0 )
        self.B = spmatrix.ll_mat_sym( self.n, 0 )

        # Analyze and factorize matrix
        self.context = _pyma27.factor( thisA, self.sqd )
        (self.rwords, self.iwords, self.ncomp, self.nrcomp, self.nicomp,
         self.n2x2pivots, self.neig, self.rank) = self.context.stats()

        self.isFullRank = (self.rank == self.n)
コード例 #3
0
ファイル: pyma27.py プロジェクト: vishalbelsare/nlpy
    def __init__(self, A, **kwargs):
        """
        Create a PyMa27Context object representing a context to solve
        the square symmetric linear system of equations

            A x = b.
    
        A should be given in ll_mat format and should be symmetric.
        The system will first be analyzed and factorized, for later
        solution. Residuals will be computed dynamically if requested.

        The factorization is a multi-frontal variant of the Bunch-Parlett
        factorization, i.e.

            A = L B Lt

        where L is unit lower triangular, and B is symmetric and block diagonal
        with either 1x1 or 2x2 blocks.
        
        A special option is available is the matrix A is known to be symmetric
        (positive or negative) definite, or symmetric quasi-definite (sqd).
        SQD matrices have the general form

            [ E  Gt ]
            [ G  -F ]

        where both E and F are positive definite. As a special case, positive
        definite matrices and negative definite matrices are sqd. SQD matrices
        can be factorized with potentially much sparser factors. Moreover, the
        matrix B reduces to a diagonal matrix.

        Currently accepted keyword arguments are:

           sqd  Flag indicating symmetric quasi-definite matrix (default: False)

        Example:
            from nlpy.linalg import pyma27
            from nlpy.tools import norms
            P = pyma27.PyMa27Context( A )
            P.solve( rhs, get_resid = True )
            print norms.norm2( P.residual )

        Pyma27 relies on the sparse direct multifrontal code MA27
        from the Harwell Subroutine Library archive.
        """

        if isinstance(A, PysparseMatrix):
            thisA = A.matrix
        else:
            thisA = A

        Sils.__init__(self, thisA, **kwargs)

        # Statistics on A
        self.rwords = 0  # Number of real words used during factorization
        self.iwords = 0  #           int
        self.ncomp = 0  #           data compresses performed in analysis
        self.nrcomp = 0  #           real
        self.nicomp = 0  #           int
        self.n2x2pivots = 0  #           2x2 pivots used
        self.neig = 0  #           negative eigenvalues detected

        # Factors
        self.L = spmatrix.ll_mat(self.n, self.n, 0)
        self.B = spmatrix.ll_mat_sym(self.n, 0)

        # Analyze and factorize matrix
        self.context = _pyma27.factor(thisA, self.sqd)
        (self.rwords, self.iwords, self.ncomp, self.nrcomp, self.nicomp,
         self.n2x2pivots, self.neig, self.rank) = self.context.stats()

        self.isFullRank = (self.rank == self.n)