using MatrixMarket, SuiteSparseMatrixCollection
using Krylov, LinearOperators
using LinearAlgebra, Printf

ssmc = ssmc_db(verbose=false)
matrix = ssmc_matrices(ssmc, "HB", "illc1033")
path = fetch_ssmc(matrix, format="MM")

A = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1]).mtx"))
b = MatrixMarket.mmread(joinpath(path[1], "$(matrix.name[1])_b.mtx"))[:]
(m, n) = size(A)
@printf("System size: %d rows and %d columns\n", m, n)

# Define a regularization parameter.
λ = 1.0e-3

(x, stats) = lsqr(A, b, λ=λ, atol=0.0, btol=0.0)
show(stats)
resid = norm(A' * (A * x - b) + λ * x) / norm(b)
@printf("LSQR: Relative residual: %8.1e\n", resid)
@printf("LSQR: ‖x‖: %8.1e\n", norm(x))
 Downloading artifact: HB/illc1033.MM
System size: 1033 rows and 320 columns
SimpleStats
 niter: 1353
 solved: false
 inconsistent: true
 residuals: []
 Aresiduals: []
 κ₂(A): []
 timer: 10.94ms
 status: maximum number of iterations exceeded
LSQR: Relative residual:  1.4e-03
LSQR: ‖x‖:  9.4e+03