Python wrapper for Nvidia CUDA parallel computation API with object cleanup, automatic error checking, and convenient abstractions.
Build a GPU-accelerated solver for sparse linear systems using iterative methods.
Create a Python module that solves sparse linear systems of equations Ax = b where A is a sparse matrix. The solver should leverage GPU acceleration for improved performance on large systems.
The module should support:
The solver should accept:
row_indices: array of row indicescol_indices: array of column indicesvalues: array of non-zero valuesshape: tuple (n_rows, n_cols)The solver should return:
The implementation should:
Given a 3x3 sparse matrix A = [[4, 1, 0], [1, 3, 1], [0, 1, 2]] with b = [1, 2, 3], solve for x and verify the residual norm is below tolerance @test
Given a 5x5 diagonal sparse matrix with values [2, 3, 4, 5, 6] and b = [2, 6, 12, 20, 30], solve for x and verify x equals [1, 2, 3, 4, 5] within tolerance @test
Given a sparse matrix and applying diagonal preconditioning, verify that the solver converges in fewer iterations than without preconditioning @test
@generates
def solve_sparse_system(
row_indices,
col_indices,
values,
shape,
b,
tolerance=1e-6,
max_iterations=1000,
preconditioner="identity"
):
"""
Solves the sparse linear system Ax = b using GPU-accelerated iterative methods.
Args:
row_indices: Array of row indices for sparse matrix (COO format)
col_indices: Array of column indices for sparse matrix (COO format)
values: Array of non-zero values for sparse matrix
shape: Tuple (n_rows, n_cols) defining matrix dimensions
b: Right-hand side vector (dense array)
tolerance: Convergence tolerance for residual norm (default: 1e-6)
max_iterations: Maximum number of iterations (default: 1000)
preconditioner: Type of preconditioner - "identity" or "diagonal" (default: "identity")
Returns:
Tuple of (solution_vector, iterations, final_residual)
- solution_vector: Solution x as numpy array
- iterations: Number of iterations performed (int)
- final_residual: Final residual norm (float)
Raises:
ValueError: If matrix is not square or dimensions don't match
RuntimeError: If solver fails to converge within max_iterations
"""
passProvides GPU-accelerated sparse matrix operations and iterative solvers.
@satisfied-by
tessl i tessl/pypi-pycuda@2025.1.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10