Skip to main content

Block Quasi-Minimal-Residual sparse linear solver

Project description

BLIT Python Bindings

Python interface for the BLIT (Block Iterative) sparse linear solver library.

Installation

Prerequisites

  • Python >= 3.8
  • NumPy
  • Fortran compiler (gfortran, ifort)
  • UMFPACK/SuiteSparse library
  • BLAS/LAPACK

On Ubuntu/Debian:

sudo apt install gfortran libsuitesparse-dev libblas-dev liblapack-dev

On macOS (Homebrew):

brew install gcc suite-sparse openblas

Install

cd python
pip install .

For development:

pip install -e .

Usage

Basic Usage

import numpy as np
from blocksolver import blqmr_solve

# Define sparse matrix in CSC format (0-based indexing)
Ap = np.array([0, 2, 5, 9, 10, 12], dtype=np.int32)
Ai = np.array([0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4], dtype=np.int32)
Ax = np.array([2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.])
b = np.array([8.0, 45.0, -3.0, 3.0, 19.0])

# Solve
result = blqmr_solve(Ap, Ai, Ax, b, tol=1e-8)

print(f"Solution: {result.x}")
print(f"Converged: {result.converged}")
print(f"Iterations: {result.iter}")

With SciPy Sparse Matrices

from scipy.sparse import csc_matrix
from blocksolver import blqmr_scipy

A = csc_matrix([[4, 1, 0], [1, 3, 1], [0, 1, 2]])
b = np.array([1., 2., 3.])

x, flag = blqmr_scipy(A, b, tol=1e-10)

Multiple Right-Hand Sides

from blocksolver import blqmr_solve_multi

B = np.column_stack([b1, b2, b3])  # n x nrhs
result = blqmr_solve_multi(Ap, Ai, Ax, B)
# result.x is n x nrhs

API Reference

blqmr_solve(Ap, Ai, Ax, b, **kwargs) -> BLQMRResult

Solve sparse system Ax = b.

Parameters:

  • Ap: Column pointers (int32, length n+1)
  • Ai: Row indices (int32, length nnz)
  • Ax: Non-zero values (float64, length nnz)
  • b: Right-hand side (float64, length n)
  • tol: Convergence tolerance (default: 1e-6)
  • maxiter: Maximum iterations (default: n)
  • droptol: ILU drop tolerance (default: 0.001)
  • use_precond: Use ILU preconditioner (default: True)
  • zero_based: Input uses 0-based indexing (default: True)

Returns: BLQMRResult with attributes:

  • x: Solution vector
  • flag: 0=converged, 1=maxiter, 2=precond fail, 3=stagnation
  • iter: Iterations performed
  • relres: Relative residual
  • converged: Boolean property

Testing

make test
# or
pytest tests/ -v

License

BSD / LGPL / GPL - see LICENSE files in parent directory.

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

blocksolver-0.6.0.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file blocksolver-0.6.0.tar.gz.

File metadata

  • Download URL: blocksolver-0.6.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for blocksolver-0.6.0.tar.gz
Algorithm Hash digest
SHA256 fd6030bc4dc861c92ab60eb2b947d8c0c8d3aa184d61fd6a0848126b7107393a
MD5 ee6d35255208cef18f106903a562d68f
BLAKE2b-256 5b6a2f55f1249f740d4e6059c328f7f8754d49deca409e56cbac5b2aff1fc8fa

See more details on using hashes here.

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