blocksolver 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,103 @@
1
+ # Makefile for BLIT Python extension
2
+ #
3
+ # Run from python/ directory:
4
+ # make # Build extension
5
+ # make install # Install package
6
+ # make test # Run tests
7
+
8
+ PYTHON ?= python3
9
+ PIP ?= $(PYTHON) -m pip
10
+ F2PY ?= $(PYTHON) -m numpy.f2py
11
+
12
+ # Compilers
13
+ FC ?= gfortran
14
+ CC ?= gcc
15
+ FFLAGS ?= -O3 -fPIC -cpp
16
+ CFLAGS ?= -O3 -fPIC
17
+
18
+ # Directories
19
+ SRC_DIR = ../src
20
+
21
+ # Library paths (adjust for your system)
22
+ UMFPACK_INC ?= /usr/include/suitesparse
23
+ UMFPACK_LIB ?= /usr/lib
24
+ LIBS = -lumfpack -lamd -lcholmod -lcolamd -lsuitesparseconfig -llapack -lblas
25
+
26
+ # Sources
27
+ FORTRAN_SRC = $(SRC_DIR)/blit_const.f90 \
28
+ $(SRC_DIR)/blit_matrixutil.f90 \
29
+ $(SRC_DIR)/blit_sparseutil.f90 \
30
+ $(SRC_DIR)/blit_ilupcond.f90 \
31
+ $(SRC_DIR)/blit_blqmr.f90 \
32
+ $(SRC_DIR)/blit_blqmr_f2py.f90
33
+
34
+ C_SRC = $(SRC_DIR)/umf4_f77wrapper.c
35
+
36
+ # Signature file for f2py
37
+ SIGNATURE = blit_blqmr.pyf
38
+
39
+ MODULE = _blqmr
40
+
41
+ # ============================================================================
42
+ .PHONY: all build install install-dev wheel test clean help
43
+
44
+ all: build
45
+
46
+ # Build using setup.py (recommended)
47
+ build: setup.py
48
+ $(PYTHON) setup.py build_ext --inplace
49
+ @echo "Build complete! Run: make test"
50
+
51
+ # Direct f2py build (faster, for development)
52
+ build-direct: $(SIGNATURE)
53
+ $(F2PY) -c $(SIGNATURE) \
54
+ --f90flags="$(FFLAGS)" \
55
+ -I$(UMFPACK_INC) -L$(UMFPACK_LIB) $(LIBS) \
56
+ $(FORTRAN_SRC) $(C_SRC)
57
+ mv $(MODULE)*.so blit/
58
+ @echo "Build complete!"
59
+
60
+ # Install
61
+ install:
62
+ $(PIP) install .
63
+
64
+ # Editable install
65
+ install-dev:
66
+ $(PIP) install -e .
67
+
68
+ # Build wheel
69
+ wheel:
70
+ $(PIP) install build
71
+ $(PYTHON) -m build --wheel
72
+
73
+ # Test
74
+ test: build
75
+ $(PYTHON) -c "import blit; blit.test()"
76
+
77
+ # Pytest
78
+ pytest: build
79
+ $(PYTHON) -m pytest tests/ -v
80
+
81
+ # Clean
82
+ clean:
83
+ rm -rf build/ dist/ *.egg-info/ .eggs/
84
+ rm -f blit/*.so blit/*.pyd
85
+ rm -rf blit/__pycache__ __pycache__ tests/__pycache__
86
+ rm -rf .pytest_cache/
87
+
88
+ # Help
89
+ help:
90
+ @echo "BLIT Python Extension"
91
+ @echo ""
92
+ @echo "Targets:"
93
+ @echo " make Build extension (default)"
94
+ @echo " make build-direct Build with f2py directly"
95
+ @echo " make install Install package"
96
+ @echo " make install-dev Editable install"
97
+ @echo " make wheel Build wheel"
98
+ @echo " make test Run tests"
99
+ @echo " make clean Clean build files"
100
+ @echo ""
101
+ @echo "Environment:"
102
+ @echo " UMFPACK_INC=$(UMFPACK_INC)"
103
+ @echo " UMFPACK_LIB=$(UMFPACK_LIB)"
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.1
2
+ Name: blocksolver
3
+ Version: 0.6.0
4
+ Summary: Block Quasi-Minimal-Residual sparse linear solver
5
+ Keywords: sparse,linear-algebra,iterative-solver,qmr,fortran,umfpack
6
+ Author-Email: Qianqian Fang <q.fang@neu.edu>
7
+ License: BSD-3-Clause OR LGPL-3.0-or-later OR GPL-3.0-or-later
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
12
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Programming Language :: Fortran
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
26
+ Project-URL: Homepage, https://blit.sourceforge.net
27
+ Project-URL: Repository, https://github.com/fangq/blocksolver
28
+ Project-URL: Documentation, https://blit.sourceforge.net
29
+ Project-URL: Bug Tracker, https://github.com/fangq/blocksolver/issues
30
+ Requires-Python: >=3.8
31
+ Requires-Dist: numpy>=1.20
32
+ Requires-Dist: scipy>=1.0
33
+ Provides-Extra: fast
34
+ Requires-Dist: numba>=0.50; extra == "fast"
35
+ Provides-Extra: test
36
+ Requires-Dist: pytest>=6.0; extra == "test"
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=6.0; extra == "dev"
39
+ Requires-Dist: build; extra == "dev"
40
+ Requires-Dist: twine; extra == "dev"
41
+ Description-Content-Type: text/markdown
42
+
43
+ # BLIT Python Bindings
44
+
45
+ Python interface for the BLIT (Block Iterative) sparse linear solver library.
46
+
47
+ ## Installation
48
+
49
+ ### Prerequisites
50
+
51
+ - Python >= 3.8
52
+ - NumPy
53
+ - Fortran compiler (gfortran, ifort)
54
+ - UMFPACK/SuiteSparse library
55
+ - BLAS/LAPACK
56
+
57
+ On Ubuntu/Debian:
58
+ ```bash
59
+ sudo apt install gfortran libsuitesparse-dev libblas-dev liblapack-dev
60
+ ```
61
+
62
+ On macOS (Homebrew):
63
+ ```bash
64
+ brew install gcc suite-sparse openblas
65
+ ```
66
+
67
+ ### Install
68
+
69
+ ```bash
70
+ cd python
71
+ pip install .
72
+ ```
73
+
74
+ For development:
75
+ ```bash
76
+ pip install -e .
77
+ ```
78
+
79
+ ## Usage
80
+
81
+ ### Basic Usage
82
+
83
+ ```python
84
+ import numpy as np
85
+ from blocksolver import blqmr_solve
86
+
87
+ # Define sparse matrix in CSC format (0-based indexing)
88
+ Ap = np.array([0, 2, 5, 9, 10, 12], dtype=np.int32)
89
+ Ai = np.array([0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4], dtype=np.int32)
90
+ Ax = np.array([2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.])
91
+ b = np.array([8.0, 45.0, -3.0, 3.0, 19.0])
92
+
93
+ # Solve
94
+ result = blqmr_solve(Ap, Ai, Ax, b, tol=1e-8)
95
+
96
+ print(f"Solution: {result.x}")
97
+ print(f"Converged: {result.converged}")
98
+ print(f"Iterations: {result.iter}")
99
+ ```
100
+
101
+ ### With SciPy Sparse Matrices
102
+
103
+ ```python
104
+ from scipy.sparse import csc_matrix
105
+ from blocksolver import blqmr_scipy
106
+
107
+ A = csc_matrix([[4, 1, 0], [1, 3, 1], [0, 1, 2]])
108
+ b = np.array([1., 2., 3.])
109
+
110
+ x, flag = blqmr_scipy(A, b, tol=1e-10)
111
+ ```
112
+
113
+ ### Multiple Right-Hand Sides
114
+
115
+ ```python
116
+ from blocksolver import blqmr_solve_multi
117
+
118
+ B = np.column_stack([b1, b2, b3]) # n x nrhs
119
+ result = blqmr_solve_multi(Ap, Ai, Ax, B)
120
+ # result.x is n x nrhs
121
+ ```
122
+
123
+ ## API Reference
124
+
125
+ ### `blqmr_solve(Ap, Ai, Ax, b, **kwargs) -> BLQMRResult`
126
+
127
+ Solve sparse system Ax = b.
128
+
129
+ **Parameters:**
130
+ - `Ap`: Column pointers (int32, length n+1)
131
+ - `Ai`: Row indices (int32, length nnz)
132
+ - `Ax`: Non-zero values (float64, length nnz)
133
+ - `b`: Right-hand side (float64, length n)
134
+ - `tol`: Convergence tolerance (default: 1e-6)
135
+ - `maxiter`: Maximum iterations (default: n)
136
+ - `droptol`: ILU drop tolerance (default: 0.001)
137
+ - `use_precond`: Use ILU preconditioner (default: True)
138
+ - `zero_based`: Input uses 0-based indexing (default: True)
139
+
140
+ **Returns:** `BLQMRResult` with attributes:
141
+ - `x`: Solution vector
142
+ - `flag`: 0=converged, 1=maxiter, 2=precond fail, 3=stagnation
143
+ - `iter`: Iterations performed
144
+ - `relres`: Relative residual
145
+ - `converged`: Boolean property
146
+
147
+ ## Testing
148
+
149
+ ```bash
150
+ make test
151
+ # or
152
+ pytest tests/ -v
153
+ ```
154
+
155
+ ## License
156
+
157
+ BSD / LGPL / GPL - see LICENSE files in parent directory.
@@ -0,0 +1,115 @@
1
+ # BLIT Python Bindings
2
+
3
+ Python interface for the BLIT (Block Iterative) sparse linear solver library.
4
+
5
+ ## Installation
6
+
7
+ ### Prerequisites
8
+
9
+ - Python >= 3.8
10
+ - NumPy
11
+ - Fortran compiler (gfortran, ifort)
12
+ - UMFPACK/SuiteSparse library
13
+ - BLAS/LAPACK
14
+
15
+ On Ubuntu/Debian:
16
+ ```bash
17
+ sudo apt install gfortran libsuitesparse-dev libblas-dev liblapack-dev
18
+ ```
19
+
20
+ On macOS (Homebrew):
21
+ ```bash
22
+ brew install gcc suite-sparse openblas
23
+ ```
24
+
25
+ ### Install
26
+
27
+ ```bash
28
+ cd python
29
+ pip install .
30
+ ```
31
+
32
+ For development:
33
+ ```bash
34
+ pip install -e .
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### Basic Usage
40
+
41
+ ```python
42
+ import numpy as np
43
+ from blit import blqmr_solve
44
+
45
+ # Define sparse matrix in CSC format (0-based indexing)
46
+ Ap = np.array([0, 2, 5, 9, 10, 12], dtype=np.int32)
47
+ Ai = np.array([0, 1, 0, 2, 4, 1, 2, 3, 4, 2, 1, 4], dtype=np.int32)
48
+ Ax = np.array([2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.])
49
+ b = np.array([8.0, 45.0, -3.0, 3.0, 19.0])
50
+
51
+ # Solve
52
+ result = blqmr_solve(Ap, Ai, Ax, b, tol=1e-8)
53
+
54
+ print(f"Solution: {result.x}")
55
+ print(f"Converged: {result.converged}")
56
+ print(f"Iterations: {result.iter}")
57
+ ```
58
+
59
+ ### With SciPy Sparse Matrices
60
+
61
+ ```python
62
+ from scipy.sparse import csc_matrix
63
+ from blit import blqmr_scipy
64
+
65
+ A = csc_matrix([[4, 1, 0], [1, 3, 1], [0, 1, 2]])
66
+ b = np.array([1., 2., 3.])
67
+
68
+ x, flag = blqmr_scipy(A, b, tol=1e-10)
69
+ ```
70
+
71
+ ### Multiple Right-Hand Sides
72
+
73
+ ```python
74
+ from blit import blqmr_solve_multi
75
+
76
+ B = np.column_stack([b1, b2, b3]) # n x nrhs
77
+ result = blqmr_solve_multi(Ap, Ai, Ax, B)
78
+ # result.x is n x nrhs
79
+ ```
80
+
81
+ ## API Reference
82
+
83
+ ### `blqmr_solve(Ap, Ai, Ax, b, **kwargs) -> BLQMRResult`
84
+
85
+ Solve sparse system Ax = b.
86
+
87
+ **Parameters:**
88
+ - `Ap`: Column pointers (int32, length n+1)
89
+ - `Ai`: Row indices (int32, length nnz)
90
+ - `Ax`: Non-zero values (float64, length nnz)
91
+ - `b`: Right-hand side (float64, length n)
92
+ - `tol`: Convergence tolerance (default: 1e-6)
93
+ - `maxiter`: Maximum iterations (default: n)
94
+ - `droptol`: ILU drop tolerance (default: 0.001)
95
+ - `use_precond`: Use ILU preconditioner (default: True)
96
+ - `zero_based`: Input uses 0-based indexing (default: True)
97
+
98
+ **Returns:** `BLQMRResult` with attributes:
99
+ - `x`: Solution vector
100
+ - `flag`: 0=converged, 1=maxiter, 2=precond fail, 3=stagnation
101
+ - `iter`: Iterations performed
102
+ - `relres`: Relative residual
103
+ - `converged`: Boolean property
104
+
105
+ ## Testing
106
+
107
+ ```bash
108
+ make test
109
+ # or
110
+ pytest tests/ -v
111
+ ```
112
+
113
+ ## License
114
+
115
+ BSD / LGPL / GPL - see LICENSE files in parent directory.
@@ -0,0 +1,83 @@
1
+ """
2
+ BLIT - Block Iterative Sparse Linear Solvers
3
+
4
+ A Python interface to the BLIT Fortran library for solving sparse linear systems.
5
+ Falls back to pure-Python implementation when Fortran extension is unavailable.
6
+
7
+ Examples
8
+ --------
9
+ >>> from blit import blqmr_solve
10
+ >>> result = blqmr_solve(Ap, Ai, Ax, b)
11
+ >>> print(result.x, result.converged)
12
+
13
+ >>> # With scipy sparse matrices:
14
+ >>> from blit import blqmr_scipy
15
+ >>> x, flag = blqmr_scipy(A, b)
16
+
17
+ >>> # Direct block QMR with custom preconditioner:
18
+ >>> from blit import blqmr, make_preconditioner
19
+ >>> M1 = make_preconditioner(A, 'ilu')
20
+ >>> x, flag, relres, niter, resv = blqmr(A, b, M1=M1)
21
+
22
+ >>> # Check which backend is being used:
23
+ >>> from blit import BLQMR_EXT
24
+ >>> print("Using Fortran" if BLQMR_EXT else "Using pure Python")
25
+ """
26
+
27
+ from .blqmr import (
28
+ blqmr_solve,
29
+ blqmr_solve_multi,
30
+ blqmr_scipy,
31
+ blqmr,
32
+ BLQMRResult,
33
+ BLQMR_EXT,
34
+ qqr,
35
+ BLQMRWorkspace,
36
+ SparsePreconditioner,
37
+ DensePreconditioner,
38
+ make_preconditioner,
39
+ HAS_NUMBA,
40
+ )
41
+
42
+ __version__ = "0.8.0"
43
+ __author__ = "Qianqian Fang"
44
+
45
+ __all__ = [
46
+ "blqmr_solve",
47
+ "blqmr_solve_multi",
48
+ "blqmr_scipy",
49
+ "blqmr",
50
+ "BLQMRResult",
51
+ "BLQMR_EXT",
52
+ "HAS_NUMBA",
53
+ "qqr",
54
+ "BLQMRWorkspace",
55
+ "SparsePreconditioner",
56
+ "DensePreconditioner",
57
+ "make_preconditioner",
58
+ ]
59
+
60
+
61
+ def test():
62
+ """Run basic tests to verify installation."""
63
+ from .blqmr import _test
64
+
65
+ return _test()
66
+
67
+
68
+ def get_backend_info():
69
+ """Return information about the active backend.
70
+
71
+ Returns
72
+ -------
73
+ dict
74
+ Dictionary containing:
75
+ - 'backend': 'binary' or 'native'
76
+ - 'has_fortran': bool
77
+ - 'has_numba': bool (for Python backend acceleration)
78
+ """
79
+ return {
80
+ "backend": "binary" if BLQMR_EXT else "native",
81
+ "has_fortran": BLQMR_EXT,
82
+ "has_numba": HAS_NUMBA,
83
+ }