Linear Algebra
Linear algebra utilities for sparse optimization.
- sparsekit.linalg.lsqr_gkl(A, b, max_iter=1000, tol=1e-06, x_0=None, device=None)[source]
Solves min ||Ax - b||_2 using the LSQR algorithm, leveraging PyTorch for GPU and Golub-Kahan-Lanczos bidiagonalization.
- Parameters:
A (Tensor) – The matrix A (torch.Tensor).
b (Tensor) – The right-hand side vector b (torch.Tensor).
max_iter (int) – Maximum number of iterations (int).
tol (float) – Tolerance for convergence (float).
x_0 (Tensor | None) – Initial guess for the solution (torch.Tensor, optional).
device (device | None) – Device to perform computations on (torch.device, optional).
- Returns:
The solution vector (torch.Tensor). info: A dictionary containing information about the convergence.
- Return type:
x
- sparsekit.linalg.hard_threshold(vec, alpha, k)[source]
Keep the k largest elements of vec, selected by magnitude of alpha.
- sparsekit.linalg.soft_threshold(vec, threshold)[source]
Element-wise soft-thresholding:
sign(x) * max(abs(x) - threshold, 0).