[docs]classScipySpsolve(DirectSolver):"""Solves a linear system using ``scipy.sparse.linalg.spsolve``."""
[docs]defsolve(self,A,b,**kwargs):"""Solves the given linear system of equations Ax=b."""ifnotisinstance(A,(csr_matrix,csc_matrix)):A=A.tocsr()return(spsolve(A,b),0)
[docs]classScipyCG(IterativeSolver):"""Solves a linear system using ``scipy.sparse.linalg.cg``."""
[docs]defsolve(self,A,b,**kwargs):"""Solves the given linear system of equations Ax=b."""ifnotisinstance(A,(csr_matrix,csc_matrix)):A=A.tocsr()atol=self._get_atol(b)try:returncg(A,b,tol=self.tol,atol=atol,**kwargs)exceptTypeError:returncg(A,b,rtol=self.tol,atol=atol,**kwargs)