Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a bunch of flake8 warnings/errors #66

Merged
merged 1 commit into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
7 changes: 3 additions & 4 deletions krypy/deflation.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,11 @@ def _auto():

# perturbation
# HACK until numpy.linal.svd (and thus numpy.linalg.norm) is fixed
from scipy.linalg import svd
andrenarchy marked this conversation as resolved.
Show resolved Hide resolved
_, Rhsvd, _ = svd(Rh[:, :i])
Rhnrm = numpy.max(Rhsvd)
epsilon = PWAW_norm*(eta*(Hh_norm + G_norm) + G_norm) \
+ Rhnrm
#+ numpy.linalg.norm(Rh[:, :i], 2)
# + numpy.linalg.norm(Rh[:, :i], 2)
if epsilon == 0:
epsilon = 1e-16

Expand Down Expand Up @@ -798,8 +797,8 @@ def __init__(self, deflated_solver, mode='ritz'):
resnorm2 = Gy.T.conj().dot(S.dot(Gy))
self.resnorms[i] = numpy.sqrt(numpy.abs(resnorm2))

#elif isinstance(P, TODO):
#TODO
# elif isinstance(P, TODO):
# TODO
else:
raise utils.ArgumentError(
'Invalid projection used in deflated_solver. '
Expand Down
4 changes: 2 additions & 2 deletions krypy/linsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, A, b,
(for debugging or research purposes). Defaults to ``None``.
'''
self.N = N = len(b)
'''Dimension :math:`N` of the space :math:`\mathbb{C}^N` where the
'''Dimension :math:`N` of the space :math:`\\mathbb{C}^N` where the
linear system is defined.'''
shape = (N, N)

Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self, A, b,

.. math::

\|M M_l b\|_{M^{-1}}
\\|M M_l b\\|_{M^{-1}}
'''

def get_residual(self, z, compute_norm=False):
Expand Down
20 changes: 10 additions & 10 deletions krypy/recycling/evaluators.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _estimate_eval_intervals(ritz, indices, indices_remaining,
mu_min = mu_ints.min_abs()

# check gap assumption
#if delta_sel + delta_non_sel + eps_max - eps_min >= delta:
# if delta_sel + delta_non_sel + eps_max - eps_min >= delta:
if delta_sel + eps_max - eps_min >= delta:
raise utils.AssumptionError(
'delta_sel + delta_non_sel + eps_max - eps_min >= delta'
Expand All @@ -116,12 +116,12 @@ def _estimate_eval_intervals(ritz, indices, indices_remaining,
raise utils.AssumptionError('mu_min == 0 not allowed')

# compute eta
#eta = (delta_sel+eps_res)**2 * (
# 1/(delta-delta_non_sel-eps_max+eps_min)
# + 1/mu_min
# )
#left = - delta_non_sel + eps_min - eta
#right = delta_non_sel + eps_max + eta
# eta = (delta_sel+eps_res)**2 * (
# 1/(delta-delta_non_sel-eps_max+eps_min)
# + 1/mu_min
# )
# left = - delta_non_sel + eps_min - eta
# right = delta_non_sel + eps_max + eta
eta = (delta_sel+eps_res)**2 * (
1/(delta-eps_max+eps_min)
+ 1/mu_min
Expand Down Expand Up @@ -198,8 +198,8 @@ def evaluate(self, ritz, subset):
**self.bound_pseudo_kwargs
)

#from matplotlib import pyplot
#pyplot.semilogy(bound_pseudo)
# from matplotlib import pyplot
# pyplot.semilogy(bound_pseudo)

if len(bound_pseudo) <= 1:
raise utils.AssumptionError('no bound computed')
Expand All @@ -216,7 +216,7 @@ def evaluate(self, ritz, subset):
(bound_pseudo[1:]/bound_pseudo[0])
** (1./numpy.array(range(1, len(bound_pseudo))))
)
if alpha >= 1 or alpha==0:
if alpha >= 1 or alpha == 0:
raise utils.AssumptionError(
'Cannot compute bound because alpha == {0} >= 1'.format(
alpha))
Expand Down
6 changes: 3 additions & 3 deletions krypy/recycling/factories.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy
from .. import utils, deflation
from . import generators, evaluators
from . import generators

#__all__ = ['_DeflationVectorFactory', 'RitzFactory']
# __all__ = ['_DeflationVectorFactory', 'RitzFactory']


class _DeflationVectorFactory(object):
Expand Down Expand Up @@ -101,7 +101,7 @@ def evaluate(_subset, _evaluations):
overall_evaluations.update(evaluations)

if len(overall_evaluations) > 0:
# if there was a successfull evaluation: pick the best one
# if there was a successfull evaluation: pick the best one
selection = list(min(overall_evaluations,
key=overall_evaluations.get))
else:
Expand Down
2 changes: 1 addition & 1 deletion krypy/recycling/linsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, DeflatedSolver,

* ``'RitzApproxKrylov'``: uses the approximate Krylov subspace bound
evaluator :py:class:`krypy.recycling.evaluators.RitzApproxKrylov`.
* ``'RitzAprioriCg'``: uses the CG :math:`\kappa`-bound
* ``'RitzAprioriCg'``: uses the CG :math:`\\kappa`-bound
(:py:class:`krypy.utils.BoundCG`) as an a priori bound with
:py:class:`krypy.recycling.evaluators.RitzApriori`.
* ``'RitzAprioriMinres'``: uses the MINRES bound
Expand Down
28 changes: 13 additions & 15 deletions krypy/tests/test_deflation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import numpy
import scipy.linalg
import itertools
from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
assert_array_equal, assert_equal
from numpy.testing import assert_almost_equal, assert_array_almost_equal


def test_deflation_solver():
Expand All @@ -28,8 +27,8 @@ def test_deflation_solver():
'maxiter': 15,
'store_arnoldi': True}

#if solver is krypy.deflation.DeflatedGmres:
# params['ortho'] = 'dmgs'
# if solver is krypy.deflation.DeflatedGmres:
# params['ortho'] = 'dmgs'

yield run_deflation_solver, solver, ls, params

Expand Down Expand Up @@ -114,8 +113,8 @@ def check_Ritz(solver, ls):
numpy.ones(m+n))

# check resnorms
#assert_array_almost_equal(ritz.resnorms[sort],
# cmp_resnorms, decimal=4)
# assert_array_almost_equal(ritz.resnorms[sort],
# cmp_resnorms, decimal=4)


def test_Arnoldifyer():
Expand Down Expand Up @@ -200,7 +199,7 @@ def run_Arnoldifyer(ls, U, A_norm, Wt_sel):
/ A_norm,
0, 7)

## check projection
# check projection
assert_array_almost_equal(krypy.utils.inner(Vh, (At+F)*Vh, ip_B=ip_Minv_B),
Hh,
7)
Expand All @@ -212,16 +211,16 @@ def run_Arnoldifyer(ls, U, A_norm, Wt_sel):

# check norm of perturbation
if Rh.size > 0:
#TODO: reenable once the numpy installation on travis is up-to-date!
#assert_almost_equal(numpy.linalg.norm(Rh, 2), numpy.linalg.norm(F, 2),
# 8)
# TODO: reenable once the numpy installation on travis is up-to-date!
# assert_almost_equal(numpy.linalg.norm(Rh, 2), numpy.linalg.norm(F, 2),
# 8)
pass

# check norm of vdiff
#PWb = PW*ls.b
#assert_array_almost_equal(krypy.utils.norm(ls.M*PW*,
# ip_B=ls.get_ip_Minv_B()),
# vdiff_norm)
# PWb = PW*ls.b
# assert_array_almost_equal(krypy.utils.norm(ls.M*PW*,
# ip_B=ls.get_ip_Minv_B()),
# vdiff_norm)

# get orthonormal basis
Q, _ = krypy.utils.qr(numpy.eye(N), ip_B=ls.get_ip_Minv_B())
Expand All @@ -235,7 +234,6 @@ def _get_op_norm(op):
)



if __name__ == '__main__':
import nose
nose.main()
8 changes: 4 additions & 4 deletions krypy/tests/test_linsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import krypy.tests.test_utils as test_utils
import numpy
import itertools
from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
assert_array_equal, assert_equal
from numpy.testing import assert_almost_equal


def dictproduct(d):
Expand Down Expand Up @@ -151,7 +150,7 @@ def check_solver(sol, solver, ls, params):
Ml = krypy.utils.get_linearoperator(shape, ls.Ml)

# maxiter respected?
if not 'max_restarts' in params:
if 'max_restarts' not in params:
assert(len(sol.resnorms)-1 <= params['maxiter'])
else:
assert(len(sol.resnorms)-1 <=
Expand Down Expand Up @@ -203,9 +202,10 @@ def check_solver(sol, solver, ls, params):
# has gmres (without restarts) found the solution after max N iterations?
# (cg or minres may take longer because of roundoff errors)
if solver == krypy.linsys.Gmres and \
((not 'max_restarts' in params) or (params['max_restarts'] == 0)):
(('max_restarts' not in params) or (params['max_restarts'] == 0)):
assert (len(sol.resnorms)-1 <= ls.b.shape[0])


if __name__ == '__main__':
import nose
nose.main()
38 changes: 18 additions & 20 deletions krypy/tests/test_recycling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import krypy
import krypy.tests.test_utils as test_utils
import krypy.tests.test_linsys as test_linsys
import numpy
import itertools
Expand Down Expand Up @@ -35,29 +34,28 @@ def run_RitzFactorySimple(Solver, ls, which):
assert(len(sols[-1].resnorms) <= len(sols[0].resnorms))


#def test_SmallRitzGenerator():
# def test_SmallRitzGenerator():
#
# matrices = [test_utils.get_matrix_spd(),
# test_utils.get_matrix_hpd(),
# test_utils.get_symm_indef(),
# test_utils.get_herm_indef()]
# max_vectorss = [numpy.Inf, 2]
# for matrix, max_vectors in itertools.product(matrices, max_vectorss):
# yield run_SmallRitzGenerator, matrix, True, max_vectors
# matrices = [test_utils.get_matrix_spd(),
# test_utils.get_matrix_hpd(),
# test_utils.get_symm_indef(),
# test_utils.get_herm_indef()]
# max_vectorss = [numpy.Inf, 2]
# for matrix, max_vectors in itertools.product(matrices, max_vectorss):
# yield run_SmallRitzGenerator, matrix, True, max_vectors
#
#
#def _get_ritz(A, self_adjoint):
# linear_system = krypy.linsys.LinearSystem(A, numpy.ones((10, 1)),
# self_adjoint=True)
# deflated_solver = krypy.deflation.DeflatedGmres(linear_system,
# store_arnoldi=True)
# return krypy.deflation.Ritz(deflated_solver)
# def _get_ritz(A, self_adjoint):
# linear_system = krypy.linsys.LinearSystem(A, numpy.ones((10, 1)),
# self_adjoint=True)
# deflated_solver = krypy.deflation.DeflatedGmres(linear_system,
# store_arnoldi=True)
# return krypy.deflation.Ritz(deflated_solver)
#
#def run_SmallRitzGenerator(A, self_adjoint, max_vectors):
# ritz = _get_ritz(A, self_adjoint)
# small = krypy.recycling.generators.SmallRitz(max_vectors=max_vectors)
# pass

# def run_SmallRitzGenerator(A, self_adjoint, max_vectors):
# ritz = _get_ritz(A, self_adjoint)
# small = krypy.recycling.generators.SmallRitz(max_vectors=max_vectors)
# pass


if __name__ == '__main__':
Expand Down
27 changes: 13 additions & 14 deletions krypy/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import krypy
import numpy
import itertools
from scipy.sparse import csr_matrix
import scipy.linalg
from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
assert_array_equal, assert_equal
Expand Down Expand Up @@ -337,14 +336,14 @@ def run_hegedus(A, b, x0, M, Ml, ip_B):


def test_arnoldi():
#TODO: reactivate the complex tests once travis-ci uses newer
# numpy/scipy versions.
# TODO: reactivate the complex tests once travis-ci uses newer
# numpy/scipy versions.
matrices = [get_matrix_spd(),
#get_matrix_hpd(),
# get_matrix_hpd(),
get_matrix_symm_indef(),
#get_matrix_herm_indef(),
# get_matrix_herm_indef(),
get_matrix_nonsymm(),
#get_matrix_comp_nonsymm()
# get_matrix_comp_nonsymm()
]
vs = [numpy.ones((10, 1)), numpy.eye(10, 1)]
maxiters = [1, 5, 9, 10]
Expand All @@ -365,12 +364,12 @@ def test_arnoldi():
continue
yield run_arnoldi, A, v, maxiter, ortho, M, ip_B, An

#TODO: reactivate the complex tests once travis-ci uses newer
# numpy/scipy versions.
# TODO: reactivate the complex tests once travis-ci uses newer
# numpy/scipy versions.
matrices = [get_matrix_spd(),
#get_matrix_hpd(),
# get_matrix_hpd(),
get_matrix_symm_indef(),
#get_matrix_herm_indef()
# get_matrix_herm_indef()
]
for (matrix, v, maxiter, M, ip_B) in \
itertools.product(matrices, vs, maxiters, Ms, ip_Bs):
Expand Down Expand Up @@ -408,7 +407,7 @@ def assert_arnoldi(A, v, V, H, P, maxiter, ortho, M, ip_B,

k = H.shape[1]

#maxiter respected?
# maxiter respected?
assert(k <= maxiter)

invariant = H.shape[0] == k
Expand Down Expand Up @@ -486,9 +485,9 @@ def assert_arnoldi(A, v, V, H, P, maxiter, ortho, M, ip_B,
def test_ritz():
# Hermitian matrices
matrices_herm = [get_matrix_spd(),
#get_matrix_hpd(),
#get_matrix_symm_indef(),
#get_matrix_herm_indef(),
# get_matrix_hpd(),
# get_matrix_symm_indef(),
# get_matrix_herm_indef(),
]
matrices_nonherm = [get_matrix_nonsymm(),
get_matrix_comp_nonsymm()
Expand Down
Loading