Exemplo n.º 1
0
def test_Arnoldifyer():
    vs = [numpy.ones((10, 1)),
          numpy.r_[numpy.ones((3, 1)), numpy.zeros((7, 1))]
          ]
    for matrix in test_utils.get_matrices():
        A_norm = numpy.linalg.norm(matrix, 2)
        numpy.random.seed(0)
        Ms = [None, numpy.diag(range(1, 11))]
        Wt_sels = ['none', 'smallest', 'largest']
        for A, v, M, Wt_sel in \
                itertools.product(test_utils.get_operators(matrix),
                                  vs, Ms, Wt_sels):
            if M is None:
                Minv = None
            else:
                Minv = numpy.linalg.inv(M)
            ls = krypy.linsys.LinearSystem(A, v, M=M, Minv=Minv)

            evals, evecs = scipy.linalg.eig(ls.M*matrix)
            sort = numpy.argsort(numpy.abs(evals))
            evecs = evecs[:, sort]
            Us = [numpy.zeros((10, 0)),
                  evecs[:, -2:],
                  evecs[:, -2:] + 1e-2*numpy.random.rand(10, 2)
                  ]
            for U in Us:
                yield run_Arnoldifyer, ls, U, A_norm, Wt_sel
Exemplo n.º 2
0
def test_linsys_herm_indef():
    A = test_utils.get_matrix_herm_indef()
    Ainv = numpy.linalg.inv(A)

    # solution
    x = (1.+1.j)*numpy.ones((10,1))

    # preconditioner
    m = numpy.array(range(1,11))
    m[-1] = 1.
    M, Minv = numpy.diag(m), numpy.diag(1./m)
    params_adds = [
            { 'M': [ None ] + test_utils.get_operators(Minv) },
            { 'Ml': [ None, Ainv ] + test_utils.get_operators(Minv) },
            { 'Mr': [ None, Ainv ] + test_utils.get_operators(Minv) }
            ]
    solvers = [ krypy.linsys.minres, krypy.linsys.gmres ]
    for case in produce_cases(A, x, params_adds, solvers):
        yield case
Exemplo n.º 3
0
def test_linsys_comp_nonsymm():
    A = test_utils.get_matrix_comp_nonsymm()
    Ainv = numpy.linalg.inv(A)

    # solution
    x = (1.j+1)*numpy.ones((10,1))

    # preconditioner
    m = numpy.array(range(1,11))
    m[-1] = 1.
    M, Minv = numpy.diag(m), numpy.diag(1./m)
    params_adds = [
            { 'maxiter': [5], 'max_restarts': [20] },
            { 'M': [ None ] + test_utils.get_operators(Minv) },
            { 'Ml': [ None, Ainv ] + test_utils.get_operators(Minv) },
            { 'Mr': [ None, Ainv ] + test_utils.get_operators(Minv) }
            ]
    solvers = [ krypy.linsys.gmres ]
    for case in produce_cases(A, x, params_adds, solvers):
        yield case
Exemplo n.º 4
0
def test_linsys_symm_indef():
    A = test_utils.get_matrix_symm_indef()
    Ainv = numpy.linalg.inv(A)

    # solution
    x = numpy.ones((10, 1))

    # preconditioner
    m = numpy.array(range(1, 11))
    m[-1] = 1.
    M, Minv = numpy.diag(m), numpy.diag(1. / m)
    params_adds = [{
        'M': [None] + test_utils.get_operators(Minv)
    }, {
        'Ml': [None, Ainv] + test_utils.get_operators(Minv)
    }, {
        'Mr': [None, Ainv] + test_utils.get_operators(Minv)
    }]
    solvers = [krypy.linsys.minres, krypy.linsys.gmres]
    for case in produce_cases(A, x, params_adds, solvers):
        yield case
Exemplo n.º 5
0
def test_linsys_comp_nonsymm():
    A = test_utils.get_matrix_comp_nonsymm()
    Ainv = numpy.linalg.inv(A)

    # solution
    x = (1.j + 1) * numpy.ones((10, 1))

    # preconditioner
    m = numpy.array(range(1, 11))
    m[-1] = 1.
    M, Minv = numpy.diag(m), numpy.diag(1. / m)
    params_adds = [{
        'maxiter': [5],
        'max_restarts': [20]
    }, {
        'M': [None] + test_utils.get_operators(Minv)
    }, {
        'Ml': [None, Ainv] + test_utils.get_operators(Minv)
    }, {
        'Mr': [None, Ainv] + test_utils.get_operators(Minv)
    }]
    solvers = [krypy.linsys.gmres]
    for case in produce_cases(A, x, params_adds, solvers):
        yield case
Exemplo n.º 6
0
def produce_cases(A, x, params_adds, solvers):
    b = numpy.dot(A, x)
    params_base = {
        'A': test_utils.get_operators(A),
        'b': test_utils.get_vecs(b),
        'x0': [ None, numpy.zeros(b.shape), x ] + test_utils.get_vecs(numpy.ones(b.shape)),
        'tol': [ 1e-14, 1e-5, 1e-2 ],
        'maxiter': [ 15 ],
        'M': [ None ],
        'Ml': [ None ],
        'Mr': [ None ],
        'inner_product': [ krypy.utils.ip_euclid ],
        'exact_solution': [ None ] + test_utils.get_vecs(x)
        }

    for params_add in params_adds:
        params = dict( list(params_base.items()) + list(params_add.items()))
        for solver, param in itertools.product(solvers, dictproduct(params)):
            yield run_case, solver, param
Exemplo n.º 7
0
def produce_cases(A, x, params_adds, solvers):
    b = numpy.dot(A, x)
    params_base = {
        'A':
        test_utils.get_operators(A),
        'b':
        test_utils.get_vecs(b),
        'x0': [None, numpy.zeros(b.shape), x] +
        test_utils.get_vecs(numpy.ones(b.shape)),
        'tol': [1e-14, 1e-5, 1e-2],
        'maxiter': [15],
        'M': [None],
        'Ml': [None],
        'Mr': [None],
        'inner_product': [krypy.utils.ip_euclid],
        'exact_solution': [None] + test_utils.get_vecs(x)
    }

    for params_add in params_adds:
        params = dict(list(params_base.items()) + list(params_add.items()))
        for solver, param in itertools.product(solvers, dictproduct(params)):
            yield run_case, solver, param