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.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

congrad-0.0.5-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: congrad-0.0.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for congrad-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dd56d6a361f320d4f81c99dbcaa418e419d2dd745ea89ebf3d8bf895ac60ecdc
MD5 e826e7276785d95f082d9d50b8424066
BLAKE2b-256 b065681db0467ba31e7e4d4ac7f53a812bd9b38d23a291b78359a1336f3899a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for congrad-0.0.5.tar.gz:

Publisher: python-publish.yml on PMKielstra/PyConGrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: congrad-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for congrad-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ac5e56564907f367e4b3c180312510cb1e7b801054a87b851d6750d7e3332df3
MD5 a1b4b1bc64227dfcb81616a45e12ad9d
BLAKE2b-256 5865257bfc0c08dcf59efbc9eac1396add8f94a6ef46846b484acad63252e100

See more details on using hashes here.

Provenance

The following attestation bundles were made for congrad-0.0.5-py3-none-any.whl:

Publisher: python-publish.yml on PMKielstra/PyConGrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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