Skip to main content

Generic conjugate gradient solver that works with your favorite backend

Project description

PyConGrad

A somewhat optimized generic batch conjugate gradient algorithm that works with PyTorch, NumPy, CuPy, and whatever other backend you like as long as you code it up.

Heavily inspired by sbarratt/torch_cg and uses similar function signatures.

Installation and Usage

$ pip install congrad # If you already have either NumPy, PyTorch, CuPy, or your backend of choice installed
$ pip install congrad[numpy] # To enforce NumPy dependency
$ pip install congrad[torch] # To enforce PyTorch dependency
$ pip install congrad[cupy] # To enforce CuPy dependency
from congrad.numpy import cg_batch # Or congrad.torch or congrad.cupy

X = np.random.rand(100, 100)
A = X @ X.T + 0.001 * np.eye(100)
b = np.random.rand(100, 10) # PyConGrad expects matrix equations, so the rightmost dimension is for batching.

def A_batch(x):
    return np.matmul(A, x)

solution, solve_info = cg_batch(A_batch, b)

For more information, documentation, and detailed instructions, see the examples folder. In particular, notebook 2 shows you how to use a different batch dimension if you want to batch over vectors instead of matrices.

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

congrad-0.0.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

congrad-0.0.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file congrad-0.0.2.tar.gz.

File metadata

  • Download URL: congrad-0.0.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for congrad-0.0.2.tar.gz
Algorithm Hash digest
SHA256 48721e4f59a30b2f571ae215ea3bb9f9d62e4922ba8a0b3f74bbde1199fa4ed0
MD5 f331b8610e4bb982a010e35763ca94e2
BLAKE2b-256 1744a78b1f0c686e7c71ae3f5da4ff9fbabccc978559ddf65b6893c6d74ea31c

See more details on using hashes here.

File details

Details for the file congrad-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: congrad-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for congrad-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0966ee65ace557bd45c6b34926ab154400b2d1cab329730dbceda544ec0d864
MD5 3fece1e352b08ea07d8960c9805e25a7
BLAKE2b-256 1d118249cda03417a5a27576932df79bd9b54f449d18722ffe1cb6c8e16caa39

See more details on using hashes here.

Supported by

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