<commit_before>from sfe.base.base import *
from sfe.solvers.solvers import LinearSolver

import scipy
if scipy.version.version == "0.6.0":
    import scipy.linsolve.umfpack as um
else:
    try:
        import scipy.splinalg.dsolve.umfpack as um
    except ImportError:
        import scikits.umfpack as um

um.configure( assumeSortedIndices = True )

##
# 10.10.2007, c
class Umfpack( LinearSolver ):
    name = 'ls.umfpack'

    ##
    # 10.10.2007, c
    def __init__( self, conf, **kwargs ):
        LinearSolver.__init__( self, conf, **kwargs )
        self.umfpack = um.UmfpackContext()

        if self._presolve() and hasattr( self, 'mtx' ):
            self.umfpack.numeric( self.mtx )

    ##
    # 02.12.2005, c
    # 14.04.2006
    # 02.10.2007
    # 10.10.2007, from solve_umfpack()
    def __call__( self, rhs, conf = None, mtx = None, status = None ):
        conf = getDefault( conf, self.conf )
        mtx = getDefault( mtx, self.mtx )
        status = getDefault( status, self.status )

##    tt = time.clock()
##    vecDX = sp.solve( mtxA, vecR )
##    print "solve = ", time.clock() - tt

##     umfpack.control[um.UMFPACK_PRL] = 4
##     umfpack.control[um.UMFPACK_IRSTEP] = 10
##     umfpack.report_control()
        sol = self.umfpack( um.UMFPACK_A, mtx, rhs, autoTranspose = True )
##     umfpack.report_info()
##    tt = time.clock()
##    vecDX2 = umfpack( um.UMFPACK_At, mtxA, vecR )
##    print "solve = ", time.clock() - tt
##    print nla.norm( vecDX1 - vecDX ), nla.norm( vecDX2 - vecDX )
    
        return sol

    ##
    # 10.10.2007, c
    def _presolve( self ):
        try:
            return self.conf.presolve
        except:
            return False

##
# c: 22.02.2008
class ScipyCG( LinearSolver ):
    name = 'ls.scipy_cg'

    ##
    # c: 22.02.2008, r: 22.02.2008
    def __init__( self, conf, **kwargs ):
        from scipy.splinalg.isolve import cg
        LinearSolver.__init__( self, conf, solver = cg, **kwargs )
        
    ##
    # c: 22.02.2008, r: 22.02.2008
    def __call__( self, rhs, conf = None, mtx = None, status = None ):
        conf = getDefault( conf, self.conf )
        mtx = getDefault( mtx, self.mtx )
        status = getDefault( status, self.status )

        sol, info = self.solver( mtx, rhs, tol = conf.epsA, maxiter = conf.iMax )
        
        return sol
<commit_msg>make it work with scipy 0.6.0<commit_after>from sfe.base.base import *
from sfe.solvers.solvers import LinearSolver

import scipy
if scipy.version.version == "0.6.0":
    import scipy.linsolve.umfpack as um
else:
    try:
        import scipy.splinalg.dsolve.umfpack as um
    except ImportError:
        import scikits.umfpack as um

um.configure( assumeSortedIndices = True )

##
# 10.10.2007, c
class Umfpack( LinearSolver ):
    name = 'ls.umfpack'

    ##
    # 10.10.2007, c
    def __init__( self, conf, **kwargs ):
        LinearSolver.__init__( self, conf, **kwargs )
        self.umfpack = um.UmfpackContext()

        if self._presolve() and hasattr( self, 'mtx' ):
            self.umfpack.numeric( self.mtx )

    ##
    # 02.12.2005, c
    # 14.04.2006
    # 02.10.2007
    # 10.10.2007, from solve_umfpack()
    def __call__( self, rhs, conf = None, mtx = None, status = None ):
        conf = getDefault( conf, self.conf )
        mtx = getDefault( mtx, self.mtx )
        status = getDefault( status, self.status )

##    tt = time.clock()
##    vecDX = sp.solve( mtxA, vecR )
##    print "solve = ", time.clock() - tt

##     umfpack.control[um.UMFPACK_PRL] = 4
##     umfpack.control[um.UMFPACK_IRSTEP] = 10
##     umfpack.report_control()
        sol = self.umfpack( um.UMFPACK_A, mtx, rhs, autoTranspose = True )
##     umfpack.report_info()
##    tt = time.clock()
##    vecDX2 = umfpack( um.UMFPACK_At, mtxA, vecR )
##    print "solve = ", time.clock() - tt
##    print nla.norm( vecDX1 - vecDX ), nla.norm( vecDX2 - vecDX )
    
        return sol

    ##
    # 10.10.2007, c
    def _presolve( self ):
        try:
            return self.conf.presolve
        except:
            return False

##
# c: 22.02.2008
class ScipyCG( LinearSolver ):
    name = 'ls.scipy_cg'

    ##
    # c: 22.02.2008, r: 22.02.2008
    def __init__( self, conf, **kwargs ):
        if scipy.version.version == "0.6.0":
            from scipy.linalg import cg
        else:
            from scipy.splinalg.isolve import cg
        LinearSolver.__init__( self, conf, solver = cg, **kwargs )
        
    ##
    # c: 22.02.2008, r: 22.02.2008
    def __call__( self, rhs, conf = None, mtx = None, status = None ):
        conf = getDefault( conf, self.conf )
        mtx = getDefault( mtx, self.mtx )
        status = getDefault( status, self.status )

        sol, info = self.solver( mtx, rhs, tol = conf.epsA, maxiter = conf.iMax )
        
        return sol

{'fraction_non_alphanumeric': 0.1344275919384999, 'fraction_numerical': 0.044878454186578015, 'mean_word_length': 2.183862433862434, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462547', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1756, 'n_words': 423}