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

Uploaded Source

Built Distribution

congrad-0.0.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: congrad-0.0.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for congrad-0.0.3.tar.gz
Algorithm Hash digest
SHA256 28e9e0285d5370fc865c2b8b06b9f95ae05b75a433abf245a00053ee860b313d
MD5 8e98877c0e05e3b085392078c6e50c0b
BLAKE2b-256 27571f59d1cc6e7ef6e5711c31eb32a3f4bba1307bf5653c16368b6ddcaffd05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: congrad-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for congrad-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a86b966206538e951083431915e4cac2c5b54b753734d6749b1ffd6ca81d3710
MD5 b3e36263ca1f3b00543a22376be8997c
BLAKE2b-256 21020a815ba3e4ebe1cdb14f0c746d71b1e079f8817d16e4fc8c075105655376

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