Skip to main content

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.

Metadata

Release files for congrad 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for congrad 0.0.5
File Size Uploaded
congrad-0.0.5.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for congrad 0.0.5
File Interpreter ABI Platform
congrad-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / congrad-0.0.5.tar.gz

Download URL congrad-0.0.5.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dd56d6a361f320d4f81c99dbcaa418e419d2dd745ea89ebf3d8bf895ac60ecdc
BLAKE2b-256 checksum
How to use checksums
b065681db0467ba31e7e4d4ac7f53a812bd9b38d23a291b78359a1336f3899a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2025.

Transparency log

Release files / congrad-0.0.5-py3-none-any.whl

Download URL congrad-0.0.5-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac5e56564907f367e4b3c180312510cb1e7b801054a87b851d6750d7e3332df3
BLAKE2b-256 checksum
How to use checksums
5865257bfc0c08dcf59efbc9eac1396add8f94a6ef46846b484acad63252e100
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page