Skip to content

Commit

Permalink
update pardiso symmetric accuracy test
Browse files Browse the repository at this point in the history
 and add more descriptive Error class
  • Loading branch information
jcapriot committed Sep 26, 2024
1 parent dd14dc5 commit e3f78b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
2 changes: 2 additions & 0 deletions pymatsolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
from .direct import Solver
from .direct import SolverLU

from .solvers import PymatsolverAccuracyError

BicgJacobi = BiCGJacobi # backwards compatibility

try:
Expand Down
8 changes: 6 additions & 2 deletions pymatsolver/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import warnings


class PymatsolverAccuracyError(Exception):
pass


class Base():
_accuracy_tol = 1e-6
_check_accuracy = False
Expand Down Expand Up @@ -57,7 +61,7 @@ def _transposeClass(self):
def T(self):
"The transpose operator for this class"
if self._transposeClass is None:
raise Exception(
raise NotImplementedError(
'The transpose for the {} class is not possible.'.format(
self.__name__
)
Expand All @@ -74,7 +78,7 @@ def _compute_accuracy(self, rhs, x):
msg = 'Accuracy on solve is above tolerance: {0:e} > {1:e}'.format(
nrm, self.accuracy_tol
)
raise Exception(msg)
raise PymatsolverAccuracyError(msg)

def _solve(self, rhs):

Expand Down
30 changes: 9 additions & 21 deletions tests/test_Pardiso.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,15 @@ def test_n_threads(test_mat_data):
with pytest.raises(TypeError):
Ainv.n_threads = "2"

# class TestPardisoNotSymmetric:
#
# @classmethod
# def setup_class(cls):
# cls.A = A
# cls.rhs = rhs
# cls.sol = sol
#
# def test(self):
# rhs = self.rhs
# sol = self.sol
# Ainv = pymatsolver.Pardiso(self.A, is_symmetric=True, check_accuracy=True)
# with pytest.raises(Exception):
# Ainv * rhs
# Ainv.clean()
#
# Ainv = pymatsolver.Pardiso(self.A)
# for i in range(3):
# assert np.linalg.norm(Ainv * rhs[:, i] - sol[:, i]) < TOL
# assert np.linalg.norm(Ainv * rhs - sol, np.inf) < TOL
# Ainv.clean()
def test_inacurrate_symmetry(test_mat_data):
A, rhs, sol = test_mat_data
# make A not symmetric
D = sp.diags(np.linspace(2, 3, A.shape[0]))
A = A @ D
Ainv = pymatsolver.Pardiso(A, is_symmetric=True, check_accuracy=True)
with pytest.raises(pymatsolver.PymatsolverAccuracyError):
Ainv * rhs



def test_pardiso_fdem():
Expand Down

0 comments on commit e3f78b7

Please sign in to comment.