using Krylov, HarwellRutherfordBoeing, SuiteSparseMatrixCollection
using LinearAlgebra, Printf

ssmc = ssmc_db(verbose=false)
matrix = ssmc_matrices(ssmc, "HB", "wm2")
path = fetch_ssmc(matrix, format="RB")

A = RutherfordBoeingData(joinpath(path[1], "$(matrix.name[1]).rb")).data
(m, n) = size(A)
@printf("System size: %d rows and %d columns\n", m, n)

x_exact = A' * ones(m)
x_exact_norm = norm(x_exact)
x_exact /= x_exact_norm
b = A * x_exact
(x, stats) = cgne(A, b)
show(stats)
resid = norm(A * x - b) / norm(b)
@printf("CGNE: Relative residual: %7.1e\n", resid)
@printf("CGNE: ‖x - x*‖₂: %7.1e\n", norm(x - x_exact))
 Downloading artifact: HB/wm2.RB
System size: 207 rows and 260 columns
SimpleStats
 niter: 216
 solved: true
 inconsistent: false
 residuals: []
 Aresiduals: []
 κ₂(A): []
 timer: 1.05ms
 status: solution good enough given atol and rtol
CGNE: Relative residual: 1.5e-08
CGNE: ‖x - x*‖₂: 3.0e-07