#****************************************************#
# This file is part of OPTALG.                       #
#                                                    #
# Copyright (c) 2015, Tomas Tinoco De Rubira.        # 
#                                                    #
# OPTALG is released under the BSD 2-clause license. #
#****************************************************#

from .lin_solver import LinSolver
from scipy.sparse.linalg import splu
from scipy.sparse import csc_matrix,triu

class LinSolverSUPERLU(LinSolver):
    """
    Linear solver based on SuperLU.
    """


    def __init__(self,prop='unsymmetric'):
        """    
        Linear solver based on SuperLU.
        """

        # Parent
        LinSolver.__init__(self,prop)

        # Name
        self.name = 'superlu'
        
        # Factorization
        self.lu = None
                
    def factorize(self,A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = (A + A.T) - triu(A)

        self.lu = splu(A)
        
    def solve(self,b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """

        return self.lu.solve(b)

858ff350f98ae0b3ebdf8a3ef06caa8ca170a22e
<mask token>


class LinSolverSUPERLU(LinSolver):
    <mask token>
    <mask token>

    def factorize(self, A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = A + A.T - triu(A)
        self.lu = splu(A)

    def solve(self, b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """
        return self.lu.solve(b)

<mask token>


class LinSolverSUPERLU(LinSolver):
    <mask token>

    def __init__(self, prop='unsymmetric'):
        """    
        Linear solver based on SuperLU.
        """
        LinSolver.__init__(self, prop)
        self.name = 'superlu'
        self.lu = None

    def factorize(self, A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = A + A.T - triu(A)
        self.lu = splu(A)

    def solve(self, b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """
        return self.lu.solve(b)

<mask token>


class LinSolverSUPERLU(LinSolver):
    """
    Linear solver based on SuperLU.
    """

    def __init__(self, prop='unsymmetric'):
        """    
        Linear solver based on SuperLU.
        """
        LinSolver.__init__(self, prop)
        self.name = 'superlu'
        self.lu = None

    def factorize(self, A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = A + A.T - triu(A)
        self.lu = splu(A)

    def solve(self, b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """
        return self.lu.solve(b)

from .lin_solver import LinSolver
from scipy.sparse.linalg import splu
from scipy.sparse import csc_matrix, triu


class LinSolverSUPERLU(LinSolver):
    """
    Linear solver based on SuperLU.
    """

    def __init__(self, prop='unsymmetric'):
        """    
        Linear solver based on SuperLU.
        """
        LinSolver.__init__(self, prop)
        self.name = 'superlu'
        self.lu = None

    def factorize(self, A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = A + A.T - triu(A)
        self.lu = splu(A)

    def solve(self, b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """
        return self.lu.solve(b)

#****************************************************#
# This file is part of OPTALG.                       #
#                                                    #
# Copyright (c) 2015, Tomas Tinoco De Rubira.        # 
#                                                    #
# OPTALG is released under the BSD 2-clause license. #
#****************************************************#

from .lin_solver import LinSolver
from scipy.sparse.linalg import splu
from scipy.sparse import csc_matrix,triu

class LinSolverSUPERLU(LinSolver):
    """
    Linear solver based on SuperLU.
    """


    def __init__(self,prop='unsymmetric'):
        """    
        Linear solver based on SuperLU.
        """

        # Parent
        LinSolver.__init__(self,prop)

        # Name
        self.name = 'superlu'
        
        # Factorization
        self.lu = None
                
    def factorize(self,A):
        """
        Factorizes A.

        Parameters
        ----------
        A : matrix
           For symmetric systems, should contain only lower diagonal part.
        """
        
        A = csc_matrix(A)
        if self.prop == self.SYMMETRIC:
            A = (A + A.T) - triu(A)

        self.lu = splu(A)
        
    def solve(self,b):
        """
        Solves system Ax=b.
        
        Parameters
        ----------
        b : ndarray
        
        Returns
        -------
        x : ndarray
        """

        return self.lu.solve(b)
