pykry

Convenience wrapper for KryPy


Keywords
engineering, mathematics, numerical-methods, pypi, python
License
AML
Install
pip install pykry==0.1.5

Documentation

pykry

CircleCI codecov Code style: black PyPi Version GitHub stars

pykry is a thin wrapper around KryPy that makes using Krylov subspace methods in Python a little more convenient. Simply create the matrix and the right-hand side, then fire it up:

import numpy
import pykry

A = numpy.diag([1.0e-3] + list(range(2, 101)))
b = numpy.ones(100)

# out = pykry.cg(A, b)
# out = pykry.minres(A, b)
out = pykry.gmres(A, b)

# out.xk contains the last iterate (ideally the solution),
# out.resnorms the relative residual norms;
# there's plenty more

convergence

Owing to KryPy, pykry has a plethora of extra parameters to hand to either one of the methods.

Getting more fancy with linear operators is as easy as defining a matrix-vector multiplication:

import numpy
import pykry

n = 100
A = numpy.diag([1.0e-3] + list(range(2, n + 1)))

def dot(x):
  return A.dot(x)

linear_operator = pykry.LinearOperator((n, n), float, dot=lambda x: dot, dot_adj=dot)
b = numpy.ones(n)
out = pykry.cg(linear_operator, b)

Installation

pykry is available from the Python Package Index, so simply type

pip install -U pykry

to install or upgrade.

Testing

To run the pykry unit tests, check out this repository and type

pytest

Distribution

To create a new release

  1. bump the __version__ number,

  2. publish to PyPi and GitHub:

    make publish
    

License

pykry is published under the MIT license.