Skip to main content

Lanczos diagonalization library: Python interface with C++ implementation

Project description

CI codecov License

PyLanczos

Overview

PyLanczos is a Lanczos diagonalization library. Its core part is written in C++ as LambdaLanczos.

Usage

All samples are available here.

NumPy and SciPy matrix

matrix = np.array([[2.0, 1.0, 1.0],
                   [1.0, 2.0, 1.0],
                   [1.0, 1.0, 2.0]])

engine = PyLanczos(matrix, True, 2)  # Find 2 maximum eigenpairs
eigenvalues, eigenvectors = engine.run()
print("Eigenvalue: {}".format(eigenvalues))
print("Eigenvector:")
print(eigenvectors)

Note: Use of SciPy sparse matrix is recommended to take full advantage of Lanczos algorithm.

Customized operation

You can also attach your customized function:

tensor = np.zeros((2, 2, 2, 2), dtype='float64')
tensor[0, 0, 0, 0] = 1
# and so on...

## Matrix-vector (or tensor-matrix) multiplication function
def mv_mul(v_in, v_out):
    v_in.shape = (2, 2)
    v_out.shape = (2, 2)

    np.einsum("ijkl, kl -> ij", tensor, v_in, out=v_out, optimize="optimal")

## Calculate an "eigenmatrix" for the 4th-order tensor.
engine = PyLanczos.create_custom(mv_mul, n, 'float64', False, 1) # Find 1 minimum eigenpair
eigenvalues, eigenmatrices = engine.run()
eigenmatrices.shape = (2, 2)
print("Eigenvalue: {}".format(eigenvalues))
print("Eigenmatrix:")
print(eigenmatrices)

There is a full sample with detailed description.

Installation

pip install pylanczos

Requirements

C++11 compatible environment

License

MIT

Author

mrcdr

PyPI repository

pylanczos

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylanczos-2.1.2.tar.gz (20.8 kB view details)

Uploaded Source

File details

Details for the file pylanczos-2.1.2.tar.gz.

File metadata

  • Download URL: pylanczos-2.1.2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for pylanczos-2.1.2.tar.gz
Algorithm Hash digest
SHA256 a6b86f2af8175c4dc316e1b9e389914ecb9e07973920e36352aac3176c09abd8
MD5 e8dfd51c575957ce02ca9f6cb977c023
BLAKE2b-256 058dd4dbcda62dbaf8a749c13848a62d67ba7d5f275c70a63c41201dba7b2f62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page