parameters: (mat, b, solver=None, verbose=False, **kwargs)
return_statement: return x
docstring: r"""Direct solution after :math:`\textbf{x}` using core LinSolver.
  
      .. math::
          \textbf{A}\textbf{x} = \textbf{b}
  
      If :math:`\textbf{A}` is symmetric, sparse and positive definite.
  
      Parameters
      ----------
      mat : :gimliapi:`GIMLI::RSparseMatrix` | :gimliapi:`GIMLI::RSparseMapMatrix` |
          numpy.array
          System matrix. Need to be symmetric, sparse and positive definite.
  
      b : iterable array
          Right hand side of the equation.
  
      solver : str [None]
          Try to choose a solver, 'pg' for pygimli core cholmod or umfpack.
          'np' for numpy linalg or scipy.sparse.linalg.
          Automatic choosing if solver is None depending on matrixtype.
  
      verbose : bool [False]
          Be verbose.
  
      Returns
      -------
      x : :gimliapi:`GIMLI::RVector`
          Solution vector
docstring_summary: r"""Direct solution after :math:`\textbf{x}` using core LinSolver.
docstring_tokens: r Direct solution after : math : \ textbf { x } using core LinSolver .
function: def linSolve(mat, b, solver=None, verbose=False, **kwargs):
      r"""Direct solution after :math:`\textbf{x}` using core LinSolver.
  
      .. math::
          \textbf{A}\textbf{x} = \textbf{b}
  
      If :math:`\textbf{A}` is symmetric, sparse and positive definite.
  
      Parameters
      ----------
      mat : :gimliapi:`GIMLI::RSparseMatrix` | :gimliapi:`GIMLI::RSparseMapMatrix` |
          numpy.array
          System matrix. Need to be symmetric, sparse and positive definite.
  
      b : iterable array
          Right hand side of the equation.
  
      solver : str [None]
          Try to choose a solver, 'pg' for pygimli core cholmod or umfpack.
          'np' for numpy linalg or scipy.sparse.linalg.
          Automatic choosing if solver is None depending on matrixtype.
  
      verbose : bool [False]
          Be verbose.
  
      Returns
      -------
      x : :gimliapi:`GIMLI::RVector`
          Solution vector
      """
      ## TODO!! refactor with LinSolver
      swatch = pg.Stopwatch()
      reorder = kwargs.pop('reorder', False)
      perm = None
  
      ### determine the solver if none set
      if solver is None:
          if isinstance(mat, pg.matrix.MatrixBase):
              solver = 'pg'
          elif isinstance(mat, np.ndarray):
              solver = 'numpy'
          else:
              #import scipy.sparse
              from scipy.sparse import spmatrix
              if isinstance(mat, spmatrix):
                  solver = 'scipy'
  
      if solver == 'pg':
          ### core proxy to cholmod and LDL for float and umfpack for complex
          if reorder is True:
              pg.warning('Matrix reordering for pg core solver not yet implemented')
          _m = pg.utils.toSparseMatrix(mat)
  
          solver = pg.core.LinSolver(_m, verbose=verbose)
  
          if verbose:
              pg.info("Solving with {0}".format(solver.solverName()))
              pg.info("Matrix factorization:", swatch.duration(restart=True))
  
          x = solver.solve(b)
  
          if verbose:
              pg.info("Matrix solution:", swatch.duration())
  
      elif solver == 'numpy':
          if verbose:
              pg.info("Solving with np.linalg.solve")
  
          x = np.linalg.solve(mat, b)
  
      elif solver == 'scipy':
          # pg._r(swatch.duration(restart=True))
          _m = pg.utils.sparseMatrix2csr(mat)
          # pg._r('convert', swatch.duration(restart=True))
  
          scipy = pg.optImport('scipy', 'Used for sparse linear solver.')
          # pg._r('import', swatch.duration(restart=True))
  
          import scipy.sparse
          from scipy.sparse.linalg import spsolve
  
          if verbose:
              pg.info("Solving with scipy.sparse.spsolve")
  
          if reorder is True and 0:
  
              def permCOO(M, perm):
                  # M.indices = perm.take(M.indices)
                  # M = M.tocsc()
                  # M.indices = perm.take(M.indices)
                  # return M.tocsr()
  
                  return M[np.ix_(perm,perm)]
  
                  # print(M.row.shape, M.col.shape)
                  # rowP = perm[M.row]
                  # colP = perm[M.col]
                  # print(rowP.shape, colP.shape)
                  # MP = scipy.sparse.coo_matrix((M.data, (rowP, colP)),
                  #                              shape=M.shape)
                  # return MP
  
              #perm = scipy.sparse.csgraph.reverse_cuthill_mckee(_m)
              #pg._r('reverse_cuthill_mckee', swatch.duration(restart=True))
  
              #ax, _ = pg.show(_m)
              #_m = permCOO(_m, perm)
              #_m = permCOO(_m.tocoo(), perm).tocsr()
              #pg.show(_m, ax=ax, color='green')
  
              #pg._r('perm matrix', swatch.duration(restart=True))
  
              #x = spsolve(_m, b.array())[perm]
  
              #x = spsolve(_m, b.array()[perm])#[perm]
              #x = x[perm]
          else:
              x = spsolve(_m, b)
  
          # pg._r(swatch.duration())
      return x
function_tokens: def linSolve ( mat , b , solver = None , verbose = False , * * kwargs ) : ## TODO!! refactor with LinSolver swatch = pg . Stopwatch ( ) reorder = kwargs . pop ( 'reorder' , False ) perm = None ### determine the solver if none set if solver is None : if isinstance ( mat , pg . matrix . MatrixBase ) : solver = 'pg' elif isinstance ( mat , np . ndarray ) : solver = 'numpy' else : #import scipy.sparse from scipy . sparse import spmatrix if isinstance ( mat , spmatrix ) : solver = 'scipy' if solver == 'pg' : ### core proxy to cholmod and LDL for float and umfpack for complex if reorder is True : pg . warning ( 'Matrix reordering for pg core solver not yet implemented' ) _m = pg . utils . toSparseMatrix ( mat ) solver = pg . core . LinSolver ( _m , verbose = verbose ) if verbose : pg . info ( "Solving with {0}" . format ( solver . solverName ( ) ) ) pg . info ( "Matrix factorization:" , swatch . duration ( restart = True ) ) x = solver . solve ( b ) if verbose : pg . info ( "Matrix solution:" , swatch . duration ( ) ) elif solver == 'numpy' : if verbose : pg . info ( "Solving with np.linalg.solve" ) x = np . linalg . solve ( mat , b ) elif solver == 'scipy' : # pg._r(swatch.duration(restart=True)) _m = pg . utils . sparseMatrix2csr ( mat ) # pg._r('convert', swatch.duration(restart=True)) scipy = pg . optImport ( 'scipy' , 'Used for sparse linear solver.' ) # pg._r('import', swatch.duration(restart=True)) import scipy . sparse from scipy . sparse . linalg import spsolve if verbose : pg . info ( "Solving with scipy.sparse.spsolve" ) if reorder is True and 0 : def permCOO ( M , perm ) : # M.indices = perm.take(M.indices) # M = M.tocsc() # M.indices = perm.take(M.indices) # return M.tocsr() return M [ np . ix_ ( perm , perm ) ] # print(M.row.shape, M.col.shape) # rowP = perm[M.row] # colP = perm[M.col] # print(rowP.shape, colP.shape) # MP = scipy.sparse.coo_matrix((M.data, (rowP, colP)), #                              shape=M.shape) # return MP #perm = scipy.sparse.csgraph.reverse_cuthill_mckee(_m) #pg._r('reverse_cuthill_mckee', swatch.duration(restart=True)) #ax, _ = pg.show(_m) #_m = permCOO(_m, perm) #_m = permCOO(_m.tocoo(), perm).tocsr() #pg.show(_m, ax=ax, color='green') #pg._r('perm matrix', swatch.duration(restart=True)) #x = spsolve(_m, b.array())[perm] #x = spsolve(_m, b.array()[perm])#[perm] #x = x[perm] else : x = spsolve ( _m , b ) # pg._r(swatch.duration()) return x