421 std::function<
void(
long,
dvec*,
dvec*,
void*)> mat_vec_prod,
426 long indx, term_iter, term_iter_max;
428 double alpha, beta, rhobar, phibar, bnorm, bbnorm, cs1, sn1, psi, rho, cs, sn, theta, phi, tau, ddnorm, delta,
429 gammabar, zetabar, gamma, cs2, sn2, zeta, xxnorm, res, resid_tol, cond_tol, resid_tol_mach, temp, stop_crit_1,
430 stop_crit_2, stop_crit_3;
432 static char term_msg[8][80] = {
"The exact solution is x = x0",
433 "The residual Ax - b is small enough, given ATOL and BTOL",
434 "The least squares error is small enough, given ATOL",
435 "The estimated condition number has exceeded CONLIM",
436 "The residual Ax - b is small enough, given machine precision",
437 "The least squares error is small enough, given machine precision",
438 "The estimated condition number has exceeded machine precision",
439 "The iteration limit has been reached" };
443 " Least Squares Solution of A*x = b\n"
444 " The matrix A has %7li rows and %7li columns\n"
445 " The damping parameter is\tDAMP = %10.2e\n"
446 " ATOL = %10.2e\t\tCONDLIM = %10.2e\n"
447 " BTOL = %10.2e\t\tITERLIM = %10li\n\n",
465 for (indx = 0; indx < input->
num_cols; indx++)
485 cond_tol = DBL_EPSILON;
534 "\tISTOP = %3li\t\t\tITER = %9li\n"
535 " || A ||_F = %13.5e\tcond( A ) = %13.5e\n"
536 " || r ||_2 = %13.5e\t|| A^T r ||_2 = %13.5e\n"
537 " || b ||_2 = %13.5e\t|| x - x0 ||_2 = %13.5e\n\n",
561 " ITER || r || Compatible "
562 "||A^T r|| / ||A|| ||r|| || A || cond( A )\n\n");
565 stop_crit_2 = alpha / beta;
568 "%6li %13.5e %10.2e \t%10.2e \t%10.2e %10.2e\n",
631 phibar = cs1 * phibar;
641 rhobar = -cs * alpha;
643 phibar = sn * phibar;
649 for (indx = 0; indx < input->
num_cols; indx++)
671 gammabar = -cs2 * rho;
672 zetabar = (phi - delta * zeta) / gammabar;
678 cs2 = gammabar / gamma;
680 zeta = (phi - delta * zeta) / gamma;
712 resid_tol_mach = DBL_EPSILON + DBL_EPSILON * output->
frob_mat_norm *
724 if (stop_crit_3 <= DBL_EPSILON)
727 if (stop_crit_2 <= DBL_EPSILON)
730 if (stop_crit_1 <= resid_tol_mach)
734 if (stop_crit_3 <= cond_tol)
737 if (stop_crit_2 <= input->rel_mat_err)
740 if (stop_crit_1 <= resid_tol)
749 "%6li %13.5e %10.2e \t%10.2e \t%10.2e %10.2e\n",
783 for (indx = 0; indx < input->
num_cols; indx++)
793 "\n\tISTOP = %3li\t\t\tITER = %9li\n"
794 " || A ||_F = %13.5e\tcond( A ) = %13.5e\n"
795 " || r ||_2 = %13.5e\t|| A^T r ||_2 = %13.5e\n"
796 " || b ||_2 = %13.5e\t|| x - x0 ||_2 = %13.5e\n\n",
void lsqr(lsqr_input *input, lsqr_output *output, lsqr_work *work, std::function< void(long, dvec *, dvec *, void *)> mat_vec_prod, void *prod)
void alloc_lsqr_mem(lsqr_input **in_struct, lsqr_output **out_struct, lsqr_work **wrk_struct, long max_num_rows, long max_num_cols)