Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
11 examples/demo_cg.py
@@ -4,8 +4,17 @@
from pykrylov.cg import CG
from demo_common import demo
+import logging
import sys
if __name__ == '__main__':
- demo(CG, sys.argv[1])
+ # Create logger for CG.
+ cglog = logging.getLogger('CG')
+ cglog.setLevel(logging.INFO)
+ fmt = logging.Formatter('%(name)-2s %(levelname)-8s %(message)s')
+ hndlr = logging.StreamHandler(sys.stdout)
+ hndlr.setFormatter(fmt)
+ cglog.addHandler(hndlr)
+
+ demo(CG, sys.argv[1], check_symmetric=True, logger=cglog)
View
8 examples/demo_common.py
@@ -19,8 +19,12 @@ def demo(KSolver, mtx, **kwargs):
e = np.ones(n)
rhs = A*e
- ks = KSolver(A, reltol=1.0e-8, **kwargs)
- ks.solve(rhs, guess=1+np.arange(n, dtype=np.float), matvec_max=2*n)
+ if 'logger' in kwargs:
+ logger = kwargs.pop('logger')
+
+ ks = KSolver(A, reltol=1.0e-8, logger=logger)
+ ks.solve(rhs, guess=1+np.arange(n, dtype=np.float), matvec_max=2*n,
+ **kwargs)
err = np.linalg.norm(ks.bestSolution-e)/sqrt(n)
View
6 pykrylov/cg/cg.py
@@ -65,7 +65,9 @@ def solve(self, rhs, **kwargs):
store_resids = kwargs.get('store_resids', False)
if check_sym:
- check_symmetric(self.matvec)
+ if not check_symmetric(self.matvec):
+ self.logger.error('Coefficient matrix is not symmetric')
+ return
# Initial guess
guess_supplied = 'guess' in kwargs.keys()
@@ -109,7 +111,7 @@ def solve(self, rhs, **kwargs):
if check_curvature:
if pAp <= 0:
- self.logger.info('Coefficient matrix is not positive definite')
+ self.logger.error('Coefficient matrix is not positive definite')
self.infiniteDescent = p
definite = False
continue

No commit comments for this range

Something went wrong with that request. Please try again.