Rlinsolve/0000755000176200001440000000000014110217132012217 5ustar liggesusersRlinsolve/NAMESPACE0000644000176200001440000000066614110104134013443 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(aux.fisch) export(lsolve.bicg) export(lsolve.bicgstab) export(lsolve.cg) export(lsolve.cgs) export(lsolve.cheby) export(lsolve.gmres) export(lsolve.gs) export(lsolve.jacobi) export(lsolve.qmr) export(lsolve.sor) export(lsolve.ssor) import(Matrix) import(Rdpack) importFrom(Rcpp,evalCpp) importFrom(stats,rnorm) importFrom(utils,packageVersion) useDynLib(Rlinsolve, .registration=TRUE) Rlinsolve/LICENSE0000644000176200001440000000005714110077764013245 0ustar liggesusersYEAR: 2021 COPYRIGHT HOLDER: Rlinsolve authors Rlinsolve/man/0000755000176200001440000000000014110077625013005 5ustar liggesusersRlinsolve/man/krylov_QMR.Rd0000644000176200001440000000346414110077625015350 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/lsolve_QMR.R \name{lsolve.qmr} \alias{lsolve.qmr} \title{Quasi Minimal Residual Method} \usage{ lsolve.qmr( A, B, xinit = NA, reltol = 1e-05, maxiter = 1000, preconditioner = diag(ncol(A)), verbose = TRUE ) } \arguments{ \item{A}{an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}.} \item{B}{a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously.} \item{xinit}{a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0.} \item{reltol}{tolerance level for stopping iterations.} \item{maxiter}{maximum number of iterations allowed.} \item{preconditioner}{an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix.} \item{verbose}{a logical; \code{TRUE} to show progress of computation.} } \value{ a named list containing \describe{ \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} \item{iter}{the number of iterations required.} \item{errors}{a vector of errors for stopping criterion.} } } \description{ Quasia-Minimal Resudial(QMR) method is another remedy of the BiCG which shows rather irregular convergence behavior. It adapts to solve the reduced tridiagonal system in a least squares sense and its convergence is known to be quite smoother than BiCG. } \examples{ \dontrun{ ## Overdetermined System set.seed(100) A = matrix(rnorm(10*5),nrow=10) x = rnorm(5) b = A\%*\%x out1 = lsolve.cg(A,b) out2 = lsolve.bicg(A,b) out3 = lsolve.qmr(A,b) matout = cbind(matrix(x),out1$x, out2$x, out3$x); colnames(matout) = c("true x","CG result", "BiCG result", "QMR result") print(matout) } } \references{ \insertRef{freund_qmr:_1991}{Rlinsolve} } Rlinsolve/man/krylov_GMRES.Rd0000644000176200001440000000362014110077625015560 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/lsolve_GMRES.R \name{lsolve.gmres} \alias{lsolve.gmres} \title{Generalized Minimal Residual method} \usage{ lsolve.gmres( A, B, xinit = NA, reltol = 1e-05, maxiter = 1000, preconditioner = diag(ncol(A)), restart = (ncol(A) - 1), verbose = TRUE ) } \arguments{ \item{A}{an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}.} \item{B}{a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously.} \item{xinit}{a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0.} \item{reltol}{tolerance level for stopping iterations.} \item{maxiter}{maximum number of iterations allowed.} \item{preconditioner}{an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix.} \item{restart}{the number of iterations before restart.} \item{verbose}{a logical; \code{TRUE} to show progress of computation.} } \value{ a named list containing \describe{ \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} \item{iter}{the number of iterations required.} \item{errors}{a vector of errors for stopping criterion.} } } \description{ GMRES is a generic iterative solver for a nonsymmetric system of linear equations. As its name suggests, it approximates the solution using Krylov vectors with minimal residuals. } \examples{ ## Overdetermined System set.seed(100) A = matrix(rnorm(10*5),nrow=10) x = rnorm(5) b = A\%*\%x out1 = lsolve.cg(A,b) out3_1 = lsolve.gmres(A,b,restart=2) out3_2 = lsolve.gmres(A,b,restart=3) out3_3 = lsolve.gmres(A,b,restart=4) matout = cbind(matrix(x),out1$x, out3_1$x, out3_2$x, out3_3$x); colnames(matout) = c("true x","CG", "GMRES(2)", "GMRES(3)", "GMRES(4)") print(matout) } \references{ \insertRef{saad_gmres:_1986}{Rlinsolve} } Rlinsolve/man/krylov_CHEBY.Rd0000644000176200001440000000363214110077625015540 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/lsolve_CHEBY.R \name{lsolve.cheby} \alias{lsolve.cheby} \title{Chebyshev Method} \usage{ lsolve.cheby( A, B, xinit = NA, reltol = 1e-05, maxiter = 10000, preconditioner = diag(ncol(A)), adjsym = TRUE, verbose = TRUE ) } \arguments{ \item{A}{an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}.} \item{B}{a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously.} \item{xinit}{a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0.} \item{reltol}{tolerance level for stopping iterations.} \item{maxiter}{maximum number of iterations allowed.} \item{preconditioner}{an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix.} \item{adjsym}{a logical; \code{TRUE} to symmetrize the system by transforming the system into normal equation, \code{FALSE} otherwise.} \item{verbose}{a logical; \code{TRUE} to show progress of computation.} } \value{ a named list containing \describe{ \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} \item{iter}{the number of iterations required.} \item{errors}{a vector of errors for stopping criterion.} } } \description{ Chebyshev method - also known as Chebyshev iteration - avoids computation of inner product, enabling distributed-memory computation to be more efficient at the cost of requiring a priori knowledge on the range of spectrum for matrix \code{A}. } \examples{ ## Overdetermined System set.seed(100) A = matrix(rnorm(10*5),nrow=10) x = rnorm(5) b = A\%*\%x out1 = lsolve.sor(A,b,w=0.5) out2 = lsolve.cheby(A,b) matout = cbind(x, out1$x, out2$x); colnames(matout) = c("original x","SOR result", "Chebyshev result") print(matout) } \references{ \insertRef{gutknecht_chebyshev_2002}{Rlinsolve} } Rlinsolve/man/Rlinsolve.Rd0000644000176200001440000000625014110077625015254 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/package-Rlinsolve.R \docType{package} \name{Rlinsolve} \alias{Rlinsolve} \title{A Collection of Iterative Solvers for (Sparse) Linear System of Equations} \description{ Solving a system of linear equations is one of the most fundamental computational problems for many fields of mathematical studies, such as regression from statistics or numerical partial differential equations. We provide a list of both stationary and nonstationary solvers. Sparse matrix class from \pkg{Matrix} is also supported for large sparse system. } \section{Non-square matrix}{ For a matrix \eqn{A} of size \code{(m-by-n)}, we say the system is \strong{overdetermined} if \code{m>n}, \strong{underdetermined} if \code{mncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A)ncol(A)}, it is automatically transformed to the normal equation. Underdetermined system - \code{nrow(A). License: MIT + file LICENSE Encoding: UTF-8 Imports: Rcpp (>= 0.12.4), Matrix, Rdpack, stats, utils LinkingTo: Rcpp, RcppArmadillo RoxygenNote: 7.1.1 RdMacros: Rdpack NeedsCompilation: yes Packaged: 2021-08-21 05:04:26 UTC; kisung Author: Kisung You [aut, cre] () Maintainer: Kisung You Repository: CRAN Date/Publication: 2021-08-21 15:40:10 UTC Rlinsolve/build/0000755000176200001440000000000014110104532013315 5ustar liggesusersRlinsolve/build/partial.rdb0000644000176200001440000006131714110104532015452 0ustar liggesus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\u_!w q/ͺc/:[^^}gg^V^tO1?ͼ^^a0~~gg,OD5ƿǟRlinsolve/src/0000755000176200001440000000000014110104532013005 5ustar liggesusersRlinsolve/src/method_gs.cpp0000644000176200001440000001074014110077626015501 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Basic Iterative Solver 2-1. Gauss-Seidel Method //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.gs.single)]] Rcpp::List single_gs(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const int dflagval){ // 1. seperate terms vec d = diagvec(A); mat D = diagmat(d); mat E = -trimatl(A,-1); // omit diagonal for lower mat F = -trimatu(A, 1); // omit diagonal for upper // 2. get parameters and set ready int n = A.n_rows; arma::colvec xold = xinit; if (norm(b-A*xinit)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } //------------------------------------------------------------------------------ // Basic Iterative Solver 2-2. Gauss-Seidel Method : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.gs.single.sparse)]] Rcpp::List single_gs_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const int dflagval){ // 1. seperate terms int n = A.n_rows; arma::sp_mat D = diagmat(A); arma::sp_mat E(n,n); for (int i=1;i=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } Rlinsolve/src/krylov_bicg.cpp0000644000176200001440000001121714110077626016042 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 2-1. Biconjugate Gradient //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.bicg.single)]] Rcpp::List single_bicg(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors beta = rho/rho_1; p = z+beta*p; p_tld = z_tld+beta*p_tld; } else { p = z; p_tld = z_tld; } q = A*p; // compute residual pair q_tld = A.t()*p_tld; alpha = rho/dot(p_tld,q); x = x+alpha*p; r = r-alpha*q; r_tld = r_tld - alpha*q_tld; error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 2-2. Biconjugate Gradient : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.bicg.single.sparse)]] Rcpp::List single_bicg_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors beta = rho/rho_1; p = z+beta*p; p_tld = z_tld+beta*p_tld; } else { p = z; p_tld = z_tld; } q = A*p; // compute residual pair q_tld = A.t()*p_tld; alpha = rho/dot(p_tld,q); x = x+alpha*p; r = r-alpha*q; r_tld = r_tld - alpha*q_tld; error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/krylov_qmr.cpp0000644000176200001440000001727514110077626015747 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 5. QMR //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.qmr.single)]] Rcpp::List single_qmr(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M){ // 1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } // 3. error preparation arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors p = y_tld - (xi*delta/ep)*p; q = z_tld - (rho*delta/ep)*q; } else { p = y_tld; q = z_tld; } p_tld = A*p; ep = dot(q,p_tld); if (ep==0.0){ break; } beta = ep/delta; if (beta==0.0){ break; } v_tld = p_tld - beta*v; y = solve(M1, v_tld); rho_1 = rho; rho = norm(y); w_tld = (A.t()*q) - (beta*w); z = solve(M2.t(), w_tld); xi = norm(z); gamma_1 = gamma; theta_1 = theta; theta = rho/(gamma_1*beta); gamma = 1.0/sqrt(1.0+(theta*theta)); if (gamma==0.0){ break; } eta = -eta*rho_1*(gamma*gamma)/(beta*(gamma_1*gamma_1)); if (iter>0){ // compute adjustment d = eta*p + ((pow(theta_1*gamma,2))*d); s = eta*p_tld + ((pow(theta_1*gamma,2))*s); } else { d = eta*p; s = eta*p_tld; } x = x + d; // update approximation r = r - s; // update residual error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 5. QMR : Spasre Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.qmr.single.sparse)]] Rcpp::List single_qmr_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M, const arma::sp_mat M1, const arma::sp_mat M2){ // 1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } // 3. error preparation arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors p = y_tld - (xi*delta/ep)*p; q = z_tld - (rho*delta/ep)*q; } else { p = y_tld; q = z_tld; } p_tld = A*p; ep = dot(q,p_tld); if (ep==0.0){ break; } beta = ep/delta; if (beta==0.0){ break; } v_tld = p_tld - beta*v; y = spsolve(M1, v_tld,"lapack"); rho_1 = rho; rho = norm(y); w_tld = (A.t()*q) - (beta*w); z = spsolve(M2.t(), w_tld,"lapack"); xi = norm(z); gamma_1 = gamma; theta_1 = theta; theta = rho/(gamma_1*beta); gamma = 1.0/sqrt(1.0+(theta*theta)); if (gamma==0.0){ break; } eta = -eta*rho_1*(gamma*gamma)/(beta*(gamma_1*gamma_1)); if (iter>0){ // compute adjustment d = eta*p + ((pow(theta_1*gamma,2))*d); s = eta*p_tld + ((pow(theta_1*gamma,2))*s); } else { d = eta*p; s = eta*p_tld; } x = x + d; // update approximation r = r - s; // update residual error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/krylov_cgs.cpp0000644000176200001440000001105014110077626015705 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 4-1. Conjugate Gradient Squared //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cgs.single)]] Rcpp::List single_cgs(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M){ // 1-1. parameter settings const int n = A.n_cols; int iter=0; int flag=0; // 0 found; 1 no convergence // 1-2. pre-iteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors beta = rho/rho_1; u = r+beta*q; p = u+beta*(q+beta*p); } else { u = r; p = u; } p_hat = solve(M,p); v_hat = A*p_hat; // adjusting scalars alpha = rho/dot(r_tld,v_hat); q = u-alpha*v_hat; u_hat = solve(M,u+q); x = x+alpha*u_hat; r = r-alpha*A*u_hat; error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error <= reltol){ break; } rho_1 = rho; iter += 1; } if (error <= reltol){ flag = 0; } else if (rho==0.0){ flag = -1; } else { flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 4-2. Conjugate Gradient Squared : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cgs.single.sparse)]] Rcpp::List single_cgs_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M){ // 1-1. parameter settings const int n = A.n_cols; int iter=0; int flag=0; // 0 found; 1 no convergence // 1-2. pre-iteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vectors beta = rho/rho_1; u = r+beta*q; p = u+beta*(q+beta*p); } else { u = r; p = u; } p_hat = spsolve(M,p,"lapack"); v_hat = A*p_hat; // adjusting scalars alpha = rho/dot(r_tld,v_hat); q = u-alpha*v_hat; u_hat = spsolve(M,u+q,"lapack"); x = x+alpha*u_hat; r = r-alpha*A*u_hat; error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error <= reltol){ break; } rho_1 = rho; iter += 1; } if (error <= reltol){ flag = 0; } else if (rho==0.0){ flag = -1; } else { flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/method_jacobi.cpp0000644000176200001440000000632214110077626016320 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Basic Iterative Solver 1-1. Jacobi Method //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.jacobi.single)]] Rcpp::List single_jacobi(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double weight){ // 1. seperate terms int n = A.n_rows; arma::mat Dinv(n,n,fill::zeros); for (int it=0;it=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } //------------------------------------------------------------------------------ // Basic Iterative Solver 1-2. Jacobi Method : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.jacobi.single.sparse)]] Rcpp::List single_jacobi_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double weight){ // 1. seperate terms const int n = A.n_rows; arma::sp_mat Dinv(n,n); for (int i=0;i=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } Rlinsolve/src/krylov_cg.cpp0000644000176200001440000000760614110077626015536 0ustar liggesusers#include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 1-1. Conjugate Gradient //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cg.single)]] Rcpp::List single_cg(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M){ // 1-1. parameter settings const int n = A.n_cols; int iter=0; int flag=0; // 0 found; 1 no convergence // 1-2. pre-iteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vector beta = rho/rho_1; p = z+beta*p; } else { p = z; } q = A*p; alpha = rho/dot(p,q); x = x+alpha*p; // update approximation vector r = r-alpha*q; // compute residual error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error<=reltol){// check convergence break; } rho_1 = rho; iter += 1; } if (error>reltol){ flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 1-2. Conjugate Gradient : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cg.single.sparse)]] Rcpp::List single_cg_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M){ // 1-1. parameter settings const int n = A.n_cols; int iter=0; int flag=0; // 0 found; 1 no convergence // 1-2. pre-iteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ // direction vector beta = rho/rho_1; p = z+beta*p; } else { p = z; } q = A*p; alpha = rho/dot(p,q); x = x+alpha*p; // update approximation vector r = r-alpha*q; // compute residual error = norm(r)/bnrm2; if (iter<(maxiter-1)){ errors(iter+1) = error; } if (error<=reltol){// check convergence break; } rho_1 = rho; iter += 1; } if (error>reltol){ flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/method_sor.cpp0000644000176200001440000000637614110077626015705 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Basic Iterative Solver 3-1. SOR //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.sor.single)]] Rcpp::List single_sor(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double w){ // 1. seperate terms vec d = diagvec(A); mat D = diagmat(d); mat L = trimatl(A,-1); // omit diagonal for lower mat U = trimatu(A, 1); // omit diagonal for upper // 2. get parameters and set ready int n = A.n_rows; arma::colvec xold = xinit; if (norm(b-A*xinit)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } //------------------------------------------------------------------------------ // Basic Iterative Solver 3-2. SOR : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.sor.single.sparse)]] Rcpp::List single_sor_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double w){ // 1. seperate terms int n = A.n_rows; arma::sp_mat D = diagmat(A); arma::sp_mat L(n,n); for (int i=1;i=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } Rlinsolve/src/Makevars0000644000176200001440000000021714110077625014515 0ustar liggesusers ## optional CXX_STD = CXX11 PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) Rlinsolve/src/Makevars.win0000644000176200001440000000021714110077625015311 0ustar liggesusers ## optional CXX_STD = CXX11 PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) Rlinsolve/src/method_ssor.cpp0000644000176200001440000000762614110077626016067 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Basic Iterative Solver 4-1. SSOR //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.ssor.single)]] Rcpp::List single_ssor(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double w){ // 1. seperate terms vec d = diagvec(A); mat D = diagmat(d); mat L = trimatl(A,-1); // omit diagonal for lower mat U = trimatu(A, 1); // omit diagonal for upper // 2. get parameters and set ready int n = A.n_rows; arma::colvec xold = xinit; if (norm(b-A*xinit)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } //------------------------------------------------------------------------------ // Basic Iterative Solver 4-2. SSOR : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.ssor.single.sparse)]] Rcpp::List single_ssor_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double w){ // 1. seperate terms int n = A.n_rows; arma::sp_mat D = diagmat(A); arma::sp_mat L(n,n); for (int i=1;i=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } return res; } Rlinsolve/src/krylov_bicgstab.cpp0000644000176200001440000001272214110077626016716 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 3-1. Biconjugate Gradient Stabilized method // From NETLIB : http://www.netlib.org/templates/matlab//bicgstab.m //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.bicgstab.single)]] Rcpp::List single_bicgstab(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown rho=0; -2 breakdown omega=0; // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ beta = (rho/rho_1)*(alpha/omega); p = r+beta*(p-omega*v); } else { p = r; } p_hat = solve(M,p); v = A*p_hat; alpha = rho/(dot(r_tld,v)); s = r - alpha*v; if (norm(s)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 3-2. Biconjugate Gradient Stabilized method : sprase way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.bicgstab.single.sparse)]] Rcpp::List single_bicgstab_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown rho=0; -2 breakdown omega=0; // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ beta = (rho/rho_1)*(alpha/omega); p = r+beta*(p-omega*v); } else { p = r; } p_hat = spsolve(M,p,"lapack"); v = A*p_hat; alpha = rho/(dot(r_tld,v)); s = r - alpha*v; if (norm(s)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/krylov_gmres.cpp0000644000176200001440000001467314110077626016264 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; // Auxliary : Givens rotation matrix parameters for a and b arma::vec rotmat(double a, double b){ double c, s, temp; if (b==0.0){ c = 1.0; s = 0.0; } else if (std::pow(b,2.0)>std::pow(a,2.0)){ temp = a/b; s = 1.0/std::sqrt(static_cast(1.0+std::pow(temp,2))); c = temp*s; } else { temp = b/a; c = 1.0/std::sqrt(static_cast(1.0+std::pow(temp,2.0))); s = temp*c; } arma::vec res(2,fill::zeros); res(0) = c; res(1) = s; return(res); } //------------------------------------------------------------------------------ // Krylov Iterative Solver 7-1. GMRES //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.gmres.single)]] Rcpp::List single_gmres(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, arma::mat& M, const int restrt){ // 1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; // 2. other basics double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 7-2. GMRES : a sparse way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.gmres.single.sparse)]] Rcpp::List single_gmres_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, arma::sp_mat M, const int restrt){ // 1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; // 2. other basics double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/krylov_cheby.cpp0000644000176200001440000000752214110077626016234 0ustar liggesusers#define ARMA_DONT_PRINT_ERRORS #include "RcppArmadillo.h" // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; //------------------------------------------------------------------------------ // Krylov Iterative Solver 6-1. Chebyshev //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cheby.single)]] Rcpp::List single_cheby(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, arma::mat& M, const double eigmax, const double eigmin){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ beta = pow(c*alpha/2.0,2); alpha= 1.0/(d-beta); p = z+beta*p; } else { p = z; alpha = 2.0/d; } x = x + alpha*p; // update approximation r = r-alpha*A*p; // update residual error = norm(r)/bnrm2; if (error<=reltol){ // check convergence break; } iter += 1; } if (error>reltol){ flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } //------------------------------------------------------------------------------ // Krylov Iterative Solver 6-2. Chebyshev : Sparse Way //------------------------------------------------------------------------------ //' @keywords internal //' @noRd // [[Rcpp::export(linsolve.cheby.single.sparse)]] Rcpp::List single_cheby_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, arma::sp_mat M, const double eigmax, const double eigmin){ // 1-1. parameter settings int n = A.n_rows; int iter=0; int flag=0; // 0 found; 1 no cvgt; -1 breakdown // 1-2. Preiteration double bnrm2 = norm(b); if (bnrm2==0){ bnrm2=1.0; } arma::colvec x = xinit; if (norm(b-A*xinit)0){ beta = pow(c*alpha/2.0,2); alpha= 1.0/(d-beta); p = z+beta*p; } else { p = z; alpha = 2.0/d; } x = x + alpha*p; // update approximation r = r-alpha*A*p; // update residual error = norm(r)/bnrm2; if (error<=reltol){ // check convergence break; } iter += 1; } if (error>reltol){ flag = 1; } // 1-4. return outputs List res; res["x"] = x; res["iter"] = iter; if (iter>=maxiter){ res["errors"] = errors; } else { arma::vec newerrors = errors.subvec(0,iter); res["errors"] = newerrors; } res["flag"] = flag; return res; } Rlinsolve/src/RcppExports.cpp0000644000176200001440000005706014110077674016032 0ustar liggesusers// Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #include #include using namespace Rcpp; #ifdef RCPP_USE_GLOBAL_ROSTREAM Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // single_bicg Rcpp::List single_bicg(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M); RcppExport SEXP _Rlinsolve_single_bicg(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_bicg(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_bicg_sparse Rcpp::List single_bicg_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M); RcppExport SEXP _Rlinsolve_single_bicg_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_bicg_sparse(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_bicgstab Rcpp::List single_bicgstab(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M); RcppExport SEXP _Rlinsolve_single_bicgstab(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_bicgstab(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_bicgstab_sparse Rcpp::List single_bicgstab_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M); RcppExport SEXP _Rlinsolve_single_bicgstab_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_bicgstab_sparse(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_cg Rcpp::List single_cg(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M); RcppExport SEXP _Rlinsolve_single_cg(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_cg(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_cg_sparse Rcpp::List single_cg_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M); RcppExport SEXP _Rlinsolve_single_cg_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_cg_sparse(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_cgs Rcpp::List single_cgs(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M); RcppExport SEXP _Rlinsolve_single_cgs(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_cgs(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_cgs_sparse Rcpp::List single_cgs_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M); RcppExport SEXP _Rlinsolve_single_cgs_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_cgs_sparse(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_cheby Rcpp::List single_cheby(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, arma::mat& M, const double eigmax, const double eigmin); RcppExport SEXP _Rlinsolve_single_cheby(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP, SEXP eigmaxSEXP, SEXP eigminSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const double >::type eigmax(eigmaxSEXP); Rcpp::traits::input_parameter< const double >::type eigmin(eigminSEXP); rcpp_result_gen = Rcpp::wrap(single_cheby(A, b, xinit, reltol, maxiter, M, eigmax, eigmin)); return rcpp_result_gen; END_RCPP } // single_cheby_sparse Rcpp::List single_cheby_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, arma::sp_mat M, const double eigmax, const double eigmin); RcppExport SEXP _Rlinsolve_single_cheby_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP, SEXP eigmaxSEXP, SEXP eigminSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< arma::sp_mat >::type M(MSEXP); Rcpp::traits::input_parameter< const double >::type eigmax(eigmaxSEXP); Rcpp::traits::input_parameter< const double >::type eigmin(eigminSEXP); rcpp_result_gen = Rcpp::wrap(single_cheby_sparse(A, b, xinit, reltol, maxiter, M, eigmax, eigmin)); return rcpp_result_gen; END_RCPP } // single_gmres Rcpp::List single_gmres(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, arma::mat& M, const int restrt); RcppExport SEXP _Rlinsolve_single_gmres(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP, SEXP restrtSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const int >::type restrt(restrtSEXP); rcpp_result_gen = Rcpp::wrap(single_gmres(A, b, xinit, reltol, maxiter, M, restrt)); return rcpp_result_gen; END_RCPP } // single_gmres_sparse Rcpp::List single_gmres_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, arma::sp_mat M, const int restrt); RcppExport SEXP _Rlinsolve_single_gmres_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP, SEXP restrtSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< arma::sp_mat >::type M(MSEXP); Rcpp::traits::input_parameter< const int >::type restrt(restrtSEXP); rcpp_result_gen = Rcpp::wrap(single_gmres_sparse(A, b, xinit, reltol, maxiter, M, restrt)); return rcpp_result_gen; END_RCPP } // single_qmr Rcpp::List single_qmr(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::mat& M); RcppExport SEXP _Rlinsolve_single_qmr(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); rcpp_result_gen = Rcpp::wrap(single_qmr(A, b, xinit, reltol, maxiter, M)); return rcpp_result_gen; END_RCPP } // single_qmr_sparse Rcpp::List single_qmr_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const arma::sp_mat M, const arma::sp_mat M1, const arma::sp_mat M2); RcppExport SEXP _Rlinsolve_single_qmr_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP MSEXP, SEXP M1SEXP, SEXP M2SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M(MSEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M1(M1SEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type M2(M2SEXP); rcpp_result_gen = Rcpp::wrap(single_qmr_sparse(A, b, xinit, reltol, maxiter, M, M1, M2)); return rcpp_result_gen; END_RCPP } // single_gs Rcpp::List single_gs(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const int dflagval); RcppExport SEXP _Rlinsolve_single_gs(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP dflagvalSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const int >::type dflagval(dflagvalSEXP); rcpp_result_gen = Rcpp::wrap(single_gs(A, b, xinit, reltol, maxiter, dflagval)); return rcpp_result_gen; END_RCPP } // single_gs_sparse Rcpp::List single_gs_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const int dflagval); RcppExport SEXP _Rlinsolve_single_gs_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP dflagvalSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const int >::type dflagval(dflagvalSEXP); rcpp_result_gen = Rcpp::wrap(single_gs_sparse(A, b, xinit, reltol, maxiter, dflagval)); return rcpp_result_gen; END_RCPP } // single_jacobi Rcpp::List single_jacobi(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double weight); RcppExport SEXP _Rlinsolve_single_jacobi(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP weightSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type weight(weightSEXP); rcpp_result_gen = Rcpp::wrap(single_jacobi(A, b, xinit, reltol, maxiter, weight)); return rcpp_result_gen; END_RCPP } // single_jacobi_sparse Rcpp::List single_jacobi_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double weight); RcppExport SEXP _Rlinsolve_single_jacobi_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP weightSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type weight(weightSEXP); rcpp_result_gen = Rcpp::wrap(single_jacobi_sparse(A, b, xinit, reltol, maxiter, weight)); return rcpp_result_gen; END_RCPP } // single_sor Rcpp::List single_sor(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double w); RcppExport SEXP _Rlinsolve_single_sor(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP wSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type w(wSEXP); rcpp_result_gen = Rcpp::wrap(single_sor(A, b, xinit, reltol, maxiter, w)); return rcpp_result_gen; END_RCPP } // single_sor_sparse Rcpp::List single_sor_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double w); RcppExport SEXP _Rlinsolve_single_sor_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP wSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type w(wSEXP); rcpp_result_gen = Rcpp::wrap(single_sor_sparse(A, b, xinit, reltol, maxiter, w)); return rcpp_result_gen; END_RCPP } // single_ssor Rcpp::List single_ssor(const arma::mat& A, const arma::colvec& b, arma::colvec& xinit, const double reltol, const int maxiter, const double w); RcppExport SEXP _Rlinsolve_single_ssor(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP wSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::colvec& >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type w(wSEXP); rcpp_result_gen = Rcpp::wrap(single_ssor(A, b, xinit, reltol, maxiter, w)); return rcpp_result_gen; END_RCPP } // single_ssor_sparse Rcpp::List single_ssor_sparse(const arma::sp_mat A, const arma::sp_mat b, arma::colvec& xinit, const double reltol, const int maxiter, const double w); RcppExport SEXP _Rlinsolve_single_ssor_sparse(SEXP ASEXP, SEXP bSEXP, SEXP xinitSEXP, SEXP reltolSEXP, SEXP maxiterSEXP, SEXP wSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::sp_mat >::type A(ASEXP); Rcpp::traits::input_parameter< const arma::sp_mat >::type b(bSEXP); Rcpp::traits::input_parameter< arma::colvec& >::type xinit(xinitSEXP); Rcpp::traits::input_parameter< const double >::type reltol(reltolSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type w(wSEXP); rcpp_result_gen = Rcpp::wrap(single_ssor_sparse(A, b, xinit, reltol, maxiter, w)); return rcpp_result_gen; END_RCPP } static const R_CallMethodDef CallEntries[] = { {"_Rlinsolve_single_bicg", (DL_FUNC) &_Rlinsolve_single_bicg, 6}, {"_Rlinsolve_single_bicg_sparse", (DL_FUNC) &_Rlinsolve_single_bicg_sparse, 6}, {"_Rlinsolve_single_bicgstab", (DL_FUNC) &_Rlinsolve_single_bicgstab, 6}, {"_Rlinsolve_single_bicgstab_sparse", (DL_FUNC) &_Rlinsolve_single_bicgstab_sparse, 6}, {"_Rlinsolve_single_cg", (DL_FUNC) &_Rlinsolve_single_cg, 6}, {"_Rlinsolve_single_cg_sparse", (DL_FUNC) &_Rlinsolve_single_cg_sparse, 6}, {"_Rlinsolve_single_cgs", (DL_FUNC) &_Rlinsolve_single_cgs, 6}, {"_Rlinsolve_single_cgs_sparse", (DL_FUNC) &_Rlinsolve_single_cgs_sparse, 6}, {"_Rlinsolve_single_cheby", (DL_FUNC) &_Rlinsolve_single_cheby, 8}, {"_Rlinsolve_single_cheby_sparse", (DL_FUNC) &_Rlinsolve_single_cheby_sparse, 8}, {"_Rlinsolve_single_gmres", (DL_FUNC) &_Rlinsolve_single_gmres, 7}, {"_Rlinsolve_single_gmres_sparse", (DL_FUNC) &_Rlinsolve_single_gmres_sparse, 7}, {"_Rlinsolve_single_qmr", (DL_FUNC) &_Rlinsolve_single_qmr, 6}, {"_Rlinsolve_single_qmr_sparse", (DL_FUNC) &_Rlinsolve_single_qmr_sparse, 8}, {"_Rlinsolve_single_gs", (DL_FUNC) &_Rlinsolve_single_gs, 6}, {"_Rlinsolve_single_gs_sparse", (DL_FUNC) &_Rlinsolve_single_gs_sparse, 6}, {"_Rlinsolve_single_jacobi", (DL_FUNC) &_Rlinsolve_single_jacobi, 6}, {"_Rlinsolve_single_jacobi_sparse", (DL_FUNC) &_Rlinsolve_single_jacobi_sparse, 6}, {"_Rlinsolve_single_sor", (DL_FUNC) &_Rlinsolve_single_sor, 6}, {"_Rlinsolve_single_sor_sparse", (DL_FUNC) &_Rlinsolve_single_sor_sparse, 6}, {"_Rlinsolve_single_ssor", (DL_FUNC) &_Rlinsolve_single_ssor, 6}, {"_Rlinsolve_single_ssor_sparse", (DL_FUNC) &_Rlinsolve_single_ssor_sparse, 6}, {NULL, NULL, 0} }; RcppExport void R_init_Rlinsolve(DllInfo *dll) { R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); R_useDynamicSymbols(dll, FALSE); } Rlinsolve/R/0000755000176200001440000000000014110104130012411 5ustar liggesusersRlinsolve/R/lsolve_BICGSTAB.R0000644000176200001440000001401614110077625015322 0ustar liggesusers#' Biconjugate Gradient Stabilized Method #' #' Biconjugate Gradient Stabilized(BiCGSTAB) method is a stabilized version of Biconjugate Gradient method for nonsymmetric systems using #' evaluations with respect to \eqn{A^T} as well as \eqn{A} in matrix-vector multiplications. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A) ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.bicgstab : underdetermined case is not supported.") } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.bicgstab : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.bicgstab : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.bicgstab.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = B res = linsolve.bicgstab.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.bicgstab.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.bicgstab.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.bicgstab : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } ########################################################################### # Step 3. Finalize if ("flag" %in% names(res)){ flagval = res$flag if (flagval==0){ if (verbose){ message("* lsolve.bicgstab : convergence well achieved.") } } else if (flagval==1){ if (verbose){ message("* lsolve.bicgstab : convergence not achieved within maxiter.") } } else { if (verbose){ message("* lsolve.bicgstab : breakdown.") } } res$flag = NULL } if (verbose){ message("* lsolve.bicgstab : computations finished.") } return(res) } Rlinsolve/R/lsolve_GS.R0000644000176200001440000001303214110100661014435 0ustar liggesusers#' Gauss-Seidel method #' #' Gauss-Seidel(GS) method is an iterative algorithm for solving a system of linear equations, #' with a decomposition \eqn{A = D+L+U} where \eqn{D} is a diagonal matrix and #' \eqn{L} and {U} are strictly lower/upper triangular matrix respectively. #' For a square matrix \eqn{A}, it is required to be diagonally dominant or symmetric and positive definite. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A)1e-10){ if (verbose){ message("* lsolve.gs : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.gs : making it normal equation form via 'adjsym' flag.") } } } } # Preprocessing : gs only : symmetric method dflagval = as.integer(1) # Preprocessing : no NA or Inf if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.gs : no NA, Inf, -Inf values are allowed.") } # Preprocessing : size argument : A and B m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.gs : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.gs : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # Preprocessing : size argument : A case # Overdetermined - A'Ax = A'b # Underdetermined - not supporting this case. n = ncol(A) if (mn){ B = (t(A)%*%B) A = (t(A)%*%A) if (verbose){ message("* lsolve.gs : overdetermined case : turning into normal equation.") } } # Preprocessing : aux.is.dd if (aux.is.dd(A)==FALSE){ if (verbose){ message("* lsolve.gs : LHS matrix A is not diagonally dominant.") message("* : solution from Gauss-Seidel method is not guaranteed.") } } # Preprocessing : adjust diagonal entries for A if (any(diag(A)==0)){ cvec = rnorm(10) adjconst = cvec[sample(which(cvec!=0),1)]/(1e+5) diag(A) = diag(A)+adjconst } # Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.gs.single(A,vecB,xinit,reltol,maxiter,dflagval) } else { vecB = B res = linsolve.gs.single.sparse(A,vecB,xinit,reltol,maxiter,dflagval) } } else { x = array(0,c(n,ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.gs.single(A,vecB,xinit,reltol,maxiter,dflagval) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.gs.single.sparse(A,vecB,xinit,reltol,maxiter,dflagval) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.gs : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } # Return if (verbose){ message("* lsolve.gs : computations finished.") } return(res) } Rlinsolve/R/lsolve_SOR.R0000644000176200001440000001373714110100652014603 0ustar liggesusers#' Successive Over-Relaxation method #' #' Successive Over-Relaxation(SOR) method is a variant of Gauss-Seidel method for solving a system of linear equations, #' with a decomposition \eqn{A = D+L+U} where \eqn{D} is a diagonal matrix and #' \eqn{L} and {U} are strictly lower/upper triangular matrix respectively. #' For a square matrix \eqn{A}, it is required to be diagonally dominant or symmetric and positive definite like GS method. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A)1e-10){ if (verbose){ message("* lsolve.sor : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.sor : making it normal equation form via 'adjsym' flag.") } } } } # Preprocessing : SOR only : w if ((w<=0)||(w>=2)){ stop("* lsolve.sor : weight value w should be in (0,2).") } if (w==1){ if (verbose){ message("* lsolve.sor : w=1 : it reduces to forward Gauss-Seidel method.") } } # Preprocessing : no NA or Inf if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.sor : no NA, Inf, -Inf values are allowed.") } # Preprocessing : size argument : A and B m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.sor : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.sor : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # Preprocessing : size argument : A case # Overdetermined - A'Ax = A'b # Underdetermined - not supporting this case. n = ncol(A) if (mn){ B = (t(A)%*%B) A = (t(A)%*%A) if (verbose){ message("* lsolve.sor : overdetermined case : turning into normal equation.") } } # Preprocessing : aux.is.dd if (aux.is.dd(A)==FALSE){ if (verbose){ message("* lsolve.sor : LHS matrix A is not diagonally dominant.") } } # Preprocessing : adjust diagonal entries for A if (any(diag(A)==0)){ cvec = rnorm(10) adjconst = cvec[sample(which(cvec!=0),1)]/(1e+5) diag(A) = diag(A)+adjconst } # Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.sor.single(A,vecB,xinit,reltol,maxiter,w) } else { vecB = B res = linsolve.sor.single.sparse(A,vecB,xinit,reltol,maxiter,w) } } else { x = array(0,c(n,ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.sor.single(A,vecB,xinit,reltol,maxiter,w) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.sor.single.sparse(A,vecB,xinit,reltol,maxiter,w) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.sor : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } # Return if (verbose){ message("* lsolve.sor : computations finished.") } return(res) } Rlinsolve/R/lsolve_GMRES.R0000644000176200001440000001404014110077625015016 0ustar liggesusers#' Generalized Minimal Residual method #' #' GMRES is a generic iterative solver for a nonsymmetric system of linear equations. As its name suggests, it approximates #' the solution using Krylov vectors with minimal residuals. #' #' @param A an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}. #' @param B a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously. #' @param xinit a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0. #' @param reltol tolerance level for stopping iterations. #' @param maxiter maximum number of iterations allowed. #' @param preconditioner an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix. #' @param restart the number of iterations before restart. #' @param verbose a logical; \code{TRUE} to show progress of computation. #' #' @return a named list containing \describe{ #' \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} #' \item{iter}{the number of iterations required.} #' \item{errors}{a vector of errors for stopping criterion.} #' } #' #' @examples #' ## Overdetermined System #' set.seed(100) #' A = matrix(rnorm(10*5),nrow=10) #' x = rnorm(5) #' b = A%*%x #' #' out1 = lsolve.cg(A,b) #' out3_1 = lsolve.gmres(A,b,restart=2) #' out3_2 = lsolve.gmres(A,b,restart=3) #' out3_3 = lsolve.gmres(A,b,restart=4) #' matout = cbind(matrix(x),out1$x, out3_1$x, out3_2$x, out3_3$x); #' colnames(matout) = c("true x","CG", "GMRES(2)", "GMRES(3)", "GMRES(4)") #' print(matout) #' #' #' @references #' \insertRef{saad_gmres:_1986}{Rlinsolve} #' #' #' @rdname krylov_GMRES #' @export lsolve.gmres <- function(A,B,xinit=NA,reltol=1e-5,maxiter=1000, preconditioner=diag(ncol(A)),restart=(ncol(A)-1),verbose=TRUE){ ########################################################################### # Step 0. Initialization if (verbose){ message("* lsolve.gmres : Initialiszed.") } if (any(is.na(A))||any(is.infinite(A))||any(is.na(B))||any(is.infinite(B))){ stop("* lsolve.gmres : no NA or Inf values allowed.") } sparseformats = c("dgCMatrix","dtCMatrix","dsCMatrix") if (aux.is.sparse(A)||aux.is.sparse(B)||aux.is.sparse(preconditioner)){ A = Matrix(A,sparse=TRUE) B = Matrix(B,sparse=TRUE) preconditioner = Matrix(preconditioner,sparse=TRUE) sparseflag = TRUE } else { A = matrix(A,nrow=nrow(A)) if (is.vector(B)){ B = matrix(B) } else { B = matrix(B,nrow=nrow(B)) } preconditioner = matrix(preconditioner,nrow=nrow(preconditioner)) sparseflag = FALSE } # xinit if (length(xinit)==1){ if (is.na(xinit)){ xinit = matrix(rnorm(ncol(A))) } else { stop("* lsolve.gmres : please use a valid 'xinit'.") } } else { if (length(xinit)!=ncol(A)){ stop("* lsolve.gmres : 'xinit' has invalid size.") } xinit = matrix(xinit) } if ((restart<2)||(is.na(restart))||(is.infinite(restart))||(abs(restart-round(restart))>sqrt(.Machine$double.eps))){ stop("* lsolve.gmres : 'restart' should be a positive integer >= 2.") } restart = round(restart) if (restart>=ncol(A)){ stop("* lsolve.gmres : take a restart value smaller than ncol(A).") } ########################################################################### # Step 1. Preprocessing # 1-1. Neither NA nor Inf allowed. if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.gmres : no NA, Inf, -Inf values are allowed.") } # 1-2. Size Argument m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.gmres : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.gmres : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # 1-3. Adjusting Case if (m > ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.gmres : underdetermined case is not supported.") } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.gmres : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.gmres : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.gmres.single(A,vecB,xinit,reltol,maxiter,preconditioner,restart) } else { vecB = B res = linsolve.gmres.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,restart) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.gmres.single(A,vecB,xinit,reltol,maxiter,preconditioner,restart) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.gmres.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,restart) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.gmres : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } ########################################################################### # Step 3. Finalize if ("flag" %in% names(res)){ flagval = res$flag if (flagval==0){ if (verbose){ message("* lsolve.gmres : convergence well achieved.") } } else if (flagval==1){ if (verbose){ message("* lsolve.gmres : convergence not achieved within maxiter.") } } else { if (verbose){ message("* lsolve.gmres : breakdown.") } } res$flag = NULL } if (verbose){ message("* lsolve.gmres : computations finished.") } return(res) } Rlinsolve/R/lsolve_SSOR.R0000644000176200001440000001375114110100676014730 0ustar liggesusers#' Symmetric Successive Over-Relaxation method #' #' Symmetric Successive Over-Relaxation(SSOR) method is a variant of Gauss-Seidel method for solving a system of linear equations, #' with a decomposition \eqn{A = D+L+U} where \eqn{D} is a diagonal matrix and #' \eqn{L} and {U} are strictly lower/upper triangular matrix respectively. #' For a square matrix \eqn{A}, it is required to be diagonally dominant or symmetric and positive definite like GS method. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A)1e-10){ if (verbose){ message("* lsolve.ssor : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.ssor : making it normal equation form via 'adjsym' flag.") } } else { stop("* lsolve.ssor : SSOR must be applied to symmetric matrix A.") } } } # Preprocessing : SSOR only : w if ((w<=0)||(w>=2)){ stop("* lsolve.ssor : weight value w should be in (0,2).") } # Preprocessing : no NA or Inf if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.ssor : no NA, Inf, -Inf values are allowed.") } # Preprocessing : size argument : A and B m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.ssor : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.ssor : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # Preprocessing : size argument : A case # Overdetermined - A'Ax = A'b # Underdetermined - not supporting this case. n = ncol(A) if (mn){ B = (t(A)%*%B) A = (t(A)%*%A) if (verbose){ message("* lsolve.ssor : overdetermined case : turning into normal equation.") } } # Preprocessing : aux.is.dd if (aux.is.dd(A)==FALSE){ if (verbose){ message("* lsolve.ssor : LHS matrix A is not diagonally dominant.") } } # Preprocessing : adjust diagonal entries for A if (any(diag(A)==0)){ cvec = rnorm(10) adjconst = cvec[sample(which(cvec!=0),1)]/(1e+5) diag(A) = diag(A)+adjconst } # Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.ssor.single(A,vecB,xinit,reltol,maxiter,w) } else { vecB = B res = linsolve.ssor.single.sparse(A,vecB,xinit,reltol,maxiter,w) } } else { x = array(0,c(n,ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.ssor.single(A,vecB,xinit,reltol,maxiter,w) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.ssor.single.sparse(A,vecB,xinit,reltol,maxiter,w) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.ssor : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } # Return if (verbose){ message("* lsolve.ssor : computations finished.") } return(res) } Rlinsolve/R/lsolve_CG.R0000644000176200001440000001435614110077625014444 0ustar liggesusers#' Conjugate Gradient method #' #' Conjugate Gradient(CG) method is an iterative algorithm for solving a system of linear equations where the system #' is symmetric and positive definite. #' For a square matrix \eqn{A}, it is required to be symmetric and positive definite. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A) ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.cg : underdetermined case is not supported.") } else { ## Case 3. Square Size if (norm(abs(t(A)-A),"f")>1e-10){ if (verbose){ message("* lsolve.cg : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.cg : making it normal equation form via 'adjsym' flag.") } } } } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.cg : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.cg : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.cg.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = B res = linsolve.cg.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.cg.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.cg.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.cg : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } ########################################################################### # Step 3. Finalize if ("flag"%in%names(res)){ flagval = res$flag; if (flagval==0){ if (verbose){ message("* lsolve.cg : convergence was well achieved.") } } else { if (verbose){ message("* lsolve.cg : convergence was not achieved within maxiter.") } } res$flag = NULL } if (verbose){ message("* lsolve.cg : computations finished.") } return(res) } Rlinsolve/R/RcppExports.R0000644000176200001440000001015714110104130015031 0ustar liggesusers# Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #' @keywords internal #' @noRd linsolve.bicg.single <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_bicg`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.bicg.single.sparse <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_bicg_sparse`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.bicgstab.single <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_bicgstab`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.bicgstab.single.sparse <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_bicgstab_sparse`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.cg.single <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_cg`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.cg.single.sparse <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_cg_sparse`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.cgs.single <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_cgs`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.cgs.single.sparse <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_cgs_sparse`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.cheby.single <- function(A, b, xinit, reltol, maxiter, M, eigmax, eigmin) { .Call(`_Rlinsolve_single_cheby`, A, b, xinit, reltol, maxiter, M, eigmax, eigmin) } #' @keywords internal #' @noRd linsolve.cheby.single.sparse <- function(A, b, xinit, reltol, maxiter, M, eigmax, eigmin) { .Call(`_Rlinsolve_single_cheby_sparse`, A, b, xinit, reltol, maxiter, M, eigmax, eigmin) } #' @keywords internal #' @noRd linsolve.gmres.single <- function(A, b, xinit, reltol, maxiter, M, restrt) { .Call(`_Rlinsolve_single_gmres`, A, b, xinit, reltol, maxiter, M, restrt) } #' @keywords internal #' @noRd linsolve.gmres.single.sparse <- function(A, b, xinit, reltol, maxiter, M, restrt) { .Call(`_Rlinsolve_single_gmres_sparse`, A, b, xinit, reltol, maxiter, M, restrt) } #' @keywords internal #' @noRd linsolve.qmr.single <- function(A, b, xinit, reltol, maxiter, M) { .Call(`_Rlinsolve_single_qmr`, A, b, xinit, reltol, maxiter, M) } #' @keywords internal #' @noRd linsolve.qmr.single.sparse <- function(A, b, xinit, reltol, maxiter, M, M1, M2) { .Call(`_Rlinsolve_single_qmr_sparse`, A, b, xinit, reltol, maxiter, M, M1, M2) } #' @keywords internal #' @noRd linsolve.gs.single <- function(A, b, xinit, reltol, maxiter, dflagval) { .Call(`_Rlinsolve_single_gs`, A, b, xinit, reltol, maxiter, dflagval) } #' @keywords internal #' @noRd linsolve.gs.single.sparse <- function(A, b, xinit, reltol, maxiter, dflagval) { .Call(`_Rlinsolve_single_gs_sparse`, A, b, xinit, reltol, maxiter, dflagval) } #' @keywords internal #' @noRd linsolve.jacobi.single <- function(A, b, xinit, reltol, maxiter, weight) { .Call(`_Rlinsolve_single_jacobi`, A, b, xinit, reltol, maxiter, weight) } #' @keywords internal #' @noRd linsolve.jacobi.single.sparse <- function(A, b, xinit, reltol, maxiter, weight) { .Call(`_Rlinsolve_single_jacobi_sparse`, A, b, xinit, reltol, maxiter, weight) } #' @keywords internal #' @noRd linsolve.sor.single <- function(A, b, xinit, reltol, maxiter, w) { .Call(`_Rlinsolve_single_sor`, A, b, xinit, reltol, maxiter, w) } #' @keywords internal #' @noRd linsolve.sor.single.sparse <- function(A, b, xinit, reltol, maxiter, w) { .Call(`_Rlinsolve_single_sor_sparse`, A, b, xinit, reltol, maxiter, w) } #' @keywords internal #' @noRd linsolve.ssor.single <- function(A, b, xinit, reltol, maxiter, w) { .Call(`_Rlinsolve_single_ssor`, A, b, xinit, reltol, maxiter, w) } #' @keywords internal #' @noRd linsolve.ssor.single.sparse <- function(A, b, xinit, reltol, maxiter, w) { .Call(`_Rlinsolve_single_ssor_sparse`, A, b, xinit, reltol, maxiter, w) } Rlinsolve/R/package-Rlinsolve.R0000644000176200001440000000655614110100457016126 0ustar liggesusers#' A Collection of Iterative Solvers for (Sparse) Linear System of Equations #' #' Solving a system of linear equations is one of the most fundamental #' computational problems for many fields of mathematical studies, such as #' regression from statistics or numerical partial differential equations. #' We provide a list of both stationary and nonstationary solvers. Sparse #' matrix class from \pkg{Matrix} is also supported for large sparse system. #' #' @section Non-square matrix: #' For a matrix \eqn{A} of size \code{(m-by-n)}, we say the system is #' \strong{overdetermined} if \code{m>n}, \strong{underdetermined} if \code{mncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A) ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.cgs : underdetermined case is not supported.") } else { ## Case 3. Square Size if (norm(abs(t(A)-A),"f")>1e-10){ if (verbose){ message("* lsolve.cgs : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.cgs : making it normal equation form via 'adjsym' flag.") } } } } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.cgs : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.cgs : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.cgs.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = B res = linsolve.cgs.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.cgs.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.cgs.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.cgs : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } ########################################################################### # Step 3. Finalize if ("flag"%in%names(res)){ flagval = res$flag; if (flagval==0){ if (verbose){ message("* lsolve.cgs : convergence was well achieved.") } } else { if (verbose){ message("* lsolve.cgs : convergence was not achieved within maxiter.") } } res$flag = NULL } if (verbose){ message("* lsolve.cgs : computations finished.") } return(res) } Rlinsolve/R/lsolve_CHEBY.R0000644000176200001440000001405514110077625015001 0ustar liggesusers#' Chebyshev Method #' #' Chebyshev method - also known as Chebyshev iteration - avoids computation of inner product, #' enabling distributed-memory computation to be more efficient at the cost of requiring #' a priori knowledge on the range of spectrum for matrix \code{A}. #' #' @param A an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}. #' @param B a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously. #' @param xinit a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0. #' @param reltol tolerance level for stopping iterations. #' @param maxiter maximum number of iterations allowed. #' @param preconditioner an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix. #' @param adjsym a logical; \code{TRUE} to symmetrize the system by transforming the system into normal equation, \code{FALSE} otherwise. #' @param verbose a logical; \code{TRUE} to show progress of computation. #' #' @return a named list containing \describe{ #' \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} #' \item{iter}{the number of iterations required.} #' \item{errors}{a vector of errors for stopping criterion.} #' } #' #' @examples #' ## Overdetermined System #' set.seed(100) #' A = matrix(rnorm(10*5),nrow=10) #' x = rnorm(5) #' b = A%*%x #' #' out1 = lsolve.sor(A,b,w=0.5) #' out2 = lsolve.cheby(A,b) #' matout = cbind(x, out1$x, out2$x); #' colnames(matout) = c("original x","SOR result", "Chebyshev result") #' print(matout) #' #' @references #' \insertRef{gutknecht_chebyshev_2002}{Rlinsolve} #' #' @rdname krylov_CHEBY #' @export lsolve.cheby <- function(A,B,xinit=NA,reltol=1e-5,maxiter=10000, preconditioner=diag(ncol(A)),adjsym=TRUE,verbose=TRUE){ ########################################################################### # Step 0. Initialization if (verbose){ message("* lsolve.cheby : Initialiszed.") } if (any(is.na(A))||any(is.infinite(A))||any(is.na(B))||any(is.infinite(B))){ stop("* lsolve.cheby : no NA or Inf values allowed.") } sparseformats = c("dgCMatrix","dtCMatrix","dsCMatrix") if (aux.is.sparse(A)||aux.is.sparse(B)||aux.is.sparse(preconditioner)){ A = Matrix(A,sparse=TRUE) B = Matrix(B,sparse=TRUE) preconditioner = Matrix(preconditioner,sparse=TRUE) sparseflag = TRUE } else { A = matrix(A,nrow=nrow(A)) if (is.vector(B)){ B = matrix(B) } else { B = matrix(B,nrow=nrow(B)) } preconditioner = matrix(preconditioner,nrow=nrow(preconditioner)) sparseflag = FALSE } # xinit if (length(xinit)==1){ if (is.na(xinit)){ xinit = matrix(rnorm(ncol(A))) } else { stop("* lsolve.cheby : please use a valid 'xinit'.") } } else { if (length(xinit)!=ncol(A)){ stop("* lsolve.cheby : 'xinit' has invalid size.") } xinit = matrix(xinit) } ########################################################################### # Step 1. Preprocessing # 1-1. Neither NA nor Inf allowed. if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.cheby : no NA, Inf, -Inf values are allowed.") } # 1-2. Size Argument m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.cheby : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.cheby : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # 1-3. Adjusting Case if (m > ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.cheby : underdetermined case is not supported.") } else { ## Case 3. Square Size if (norm(abs(t(A)-A),"f")>1e-10){ if (verbose){ message("* lsolve.cheby : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.cheby : making it normal equation form via 'adjsym' flag.") } } } } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.cheby : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.cheby : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation eigs = solve(preconditioner, A) eigsdec = eigen(eigs, only.values = TRUE) eigmax = max(eigsdec$values) eigmin = min(eigsdec$values) ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.cheby.single(A,vecB,xinit,reltol,maxiter,preconditioner,eigmax,eigmin) } else { vecB = B res = linsolve.cheby.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,eigmax,eigmin) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.cheby.single(A,vecB,xinit,reltol,maxiter,preconditioner,eigmax,eigmin) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.cheby.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,eigmax,eigmin) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.cheby : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } if ("flag"%in%names(res)){ flagval = res$flag; if (flagval==0){ if (verbose){ message("* lsolve.cheby : convergence was well achieved.") } } else { if (verbose){ message("* lsolve.cheby : convergence was not achieved within maxiter.") } } res$flag = NULL } return(res) if (verbose){ message("* lsolve.cheby : computations finished.") } } Rlinsolve/R/lsolve_QMR.R0000644000176200001440000001471014110077625014604 0ustar liggesusers#' Quasi Minimal Residual Method #' #' Quasia-Minimal Resudial(QMR) method is another remedy of the BiCG which shows #' rather irregular convergence behavior. It adapts to solve the reduced tridiagonal system #' in a least squares sense and its convergence is known to be quite smoother than BiCG. #' #' @param A an \eqn{(m\times n)} dense or sparse matrix. See also \code{\link[Matrix]{sparseMatrix}}. #' @param B a vector of length \eqn{m} or an \eqn{(m\times k)} matrix (dense or sparse) for solving \eqn{k} systems simultaneously. #' @param xinit a length-\eqn{n} vector for initial starting point. \code{NA} to start from a random initial point near 0. #' @param reltol tolerance level for stopping iterations. #' @param maxiter maximum number of iterations allowed. #' @param preconditioner an \eqn{(n\times n)} preconditioning matrix; default is an identity matrix. #' @param verbose a logical; \code{TRUE} to show progress of computation. #' #' @return a named list containing \describe{ #' \item{x}{solution; a vector of length \eqn{n} or a matrix of size \eqn{(n\times k)}.} #' \item{iter}{the number of iterations required.} #' \item{errors}{a vector of errors for stopping criterion.} #' } #' #' @examples #' \dontrun{ #' ## Overdetermined System #' set.seed(100) #' A = matrix(rnorm(10*5),nrow=10) #' x = rnorm(5) #' b = A%*%x #' #' out1 = lsolve.cg(A,b) #' out2 = lsolve.bicg(A,b) #' out3 = lsolve.qmr(A,b) #' matout = cbind(matrix(x),out1$x, out2$x, out3$x); #' colnames(matout) = c("true x","CG result", "BiCG result", "QMR result") #' print(matout) #' } #' #' @references #' \insertRef{freund_qmr:_1991}{Rlinsolve} #' #' @rdname krylov_QMR #' @export lsolve.qmr <- function(A,B,xinit=NA,reltol=1e-5,maxiter=1000, preconditioner=diag(ncol(A)),verbose=TRUE){ ########################################################################### # Step 0. Initialization if (verbose){ message("* lsolve.qmr : Initialiszed.") } if (any(is.na(A))||any(is.infinite(A))||any(is.na(B))||any(is.infinite(B))){ stop("* lsolve.qmr : no NA or Inf values allowed.") } sparseformats = c("dgCMatrix","dtCMatrix","dsCMatrix") if (aux.is.sparse(A)||aux.is.sparse(B)||aux.is.sparse(preconditioner)){ A = Matrix(A,sparse=TRUE) B = Matrix(B,sparse=TRUE) preconditioner = Matrix(preconditioner,sparse=TRUE) sparseflag = TRUE } else { A = matrix(A,nrow=nrow(A)) if (is.vector(B)){ B = matrix(B) } else { B = matrix(B,nrow=nrow(B)) } preconditioner = matrix(preconditioner,nrow=nrow(preconditioner)) sparseflag = FALSE } # xinit if (length(xinit)==1){ if (is.na(xinit)){ xinit = matrix(rnorm(ncol(A))) } else { stop("* lsolve.qmr : please use a valid 'xinit'.") } } else { if (length(xinit)!=ncol(A)){ stop("* lsolve.qmr : 'xinit' has invalid size.") } xinit = matrix(xinit) } ########################################################################### # Step 1. Preprocessing # 1-1. Neither NA nor Inf allowed. if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.qmr : no NA, Inf, -Inf values are allowed.") } # 1-2. Size Argument m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.qmr : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.qmr : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # 1-3. Adjusting Case if (m > ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.qmr : underdetermined case is not supported.") } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.qmr : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.qmr : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (sparseflag){ luM = lu(preconditioner) M1 = luM@L M2 = luM@U } if (!sparseflag){ vecB = as.vector(B) res = linsolve.qmr.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = B res = linsolve.qmr.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,M1,M2) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors = list() if (sparseflag){ luM = lu(preconditioner) M1 = luM@L M2 = luM@U } for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.qmr.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.qmr.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner,M1,M2) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.qmr : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } ########################################################################### # Step 3. Finalize if ("flag" %in% names(res)){ flagval = res$flag if (flagval==0){ if (verbose){ message("* lsolve.qmr : convergence well achieved.") } } else if (flagval==1){ if (verbose){ message("* lsolve.qmr : convergence not achieved within maxiter.") } } else if (flagval==-1){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'rho' value.") } } else if (flagval==-2){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'beta' value.") } } else if (flagval==-3){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'gamma' value.") } } else if (flagval==-4){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'delta' value.") } } else if (flagval==-5){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'ep' value.") } } else if (flagval==-6){ if (verbose){ message("* lsolve.qmr : breakdown due to degenerate 'xi' value.") } } res$flag = NULL } if (verbose){ message("* lsolve.qmr : computations finished.") } return(res) } Rlinsolve/R/lsolve_JACOBI.R0000644000176200001440000001462314110100666015067 0ustar liggesusers#' Jacobi method #' #' Jacobi method is an iterative algorithm for solving a system of linear equations, #' with a decomposition \eqn{A = D+R} where \eqn{D} is a diagonal matrix. #' For a square matrix \eqn{A}, it is required to be diagonally dominant. For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A)1e-10){ if (verbose){ message("* lsolve.jacobi : A may not be symmetric.") } if (adjsym){ B = t(A)%*%B A = t(A)%*%A if (verbose){ message("* lsolve.jacobi : making it normal equation form via 'adjsym' flag.") } } } } # Preprocessing : JACOBI ONLY : weight should be (0,1] if ((weight<=0)||(weight>1)){ stop("* lsolve.jacobi : weight should be a positive real number in (0,1].") } # Preprocessing : no NA or Inf if (any(is.infinite(A))||any(is.na(A))||any(is.infinite(B))||any(is.na(B))){ stop("* lsolve.jacobi : no NA, Inf, -Inf values are allowed.") } # Preprocessing : size argument : A and B m = nrow(A) if (is.vector(B)){ mB = length(B) if (m!=mB){ stop("* lsolve.jacobi : a vector B should have a length of nrow(A).") } } else { mB = nrow(B) if (m!=mB){ stop("* lsolve.jacobi : an input matrix B should have the same number of rows from A.") } } if (is.vector(B)){ B = as.matrix(B) } # Preprocessing : size argument : A case # Overdetermined - A'Ax = A'b # Underdetermined - not supporting this case. n = ncol(A) if (mn){ B = (t(A)%*%B) A = (t(A)%*%A) if (verbose){ message("* lsolve.jacobi : overdetermined case : turning into normal equation.") } } # Preprocessing : aux.is.dd if (aux.is.dd(A)==FALSE){ if (verbose){ message("* lsolve.jacobi : LHS matrix A is not diagonally dominant.") message("* : solution from Jacobi method is not guaranteed.") } } # # Preprocessing : aux.is.dd # if (aux.is.dd(A)==FALSE){ # if (verbose){ # message("* lsolve.jacobi : LHS matrix A is not diagonally dominant.") # message("* : solution from Jacobi method is not guaranteed.") # } # } # Preprocessing : adjust diagonal entries for A if (any(diag(A)==0)){ cvec = rnorm(10) adjconst = cvec[sample(which(cvec!=0),1)]/(1e+5) diag(A) = diag(A)+adjconst } # Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.jacobi.single(A,vecB,xinit,reltol,maxiter,weight) } else { vecB = B res = linsolve.jacobi.single.sparse(A,vecB,xinit,reltol,maxiter,weight) } } else { x = array(0,c(n,ncolB)) iter = array(0,c(1,ncolB)) errors = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.jacobi.single(A,vecB,xinit,reltol,maxiter,weight) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.jacobi.single.sparse(A,vecB,xinit,reltol,maxiter,weight) } x[,i] = tmpres$x iter[i] = tmpres$iter errors[[i]] = tmpres$errors if (verbose){ message(paste("* lsolve.jacobi : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors"=errors) } # Return if (verbose){ message("* lsolve.jacobi : computations finished.") } return(res) } Rlinsolve/R/lsolve_BICG.R0000644000176200001440000001367214110077625014657 0ustar liggesusers#' Biconjugate Gradient method #' #' Biconjugate Gradient(BiCG) method is a modification of Conjugate Gradient for nonsymmetric systems using #' evaluations with respect to \eqn{A^T} as well as \eqn{A} in matrix-vector multiplications. #' For an overdetermined system where \code{nrow(A)>ncol(A)}, #' it is automatically transformed to the normal equation. Underdetermined system - #' \code{nrow(A) ncol(A)){ ## Case 1. Overdetermined B = t(A)%*%B A = t(A)%*%A } else if (m < ncol(A)){ ## Case 2. Underdetermined stop("* lsolve.bicg : underdetermined case is not supported.") } # 1-4. Preconditioner : only valid for square case if (!all.equal(dim(A),dim(preconditioner))){ stop("* lsolve.bicg : Preconditioner is a size-matching.") } if (verbose){message("* lsolve.bicg : preprocessing finished ...")} ########################################################################### # Step 2. Main Computation ncolB = ncol(B) if (ncolB==1){ if (!sparseflag){ vecB = as.vector(B) res = linsolve.bicg.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = B res = linsolve.bicg.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } } else { x = array(0,c(ncol(A),ncolB)) iter = array(0,c(1,ncolB)) errors1 = list() errors2 = list() for (i in 1:ncolB){ if (!sparseflag){ vecB = as.vector(B[,i]) tmpres = linsolve.bicg.single(A,vecB,xinit,reltol,maxiter,preconditioner) } else { vecB = Matrix(B[,i],sparse=TRUE) tmpres = linsolve.bicg.single.sparse(A,vecB,xinit,reltol,maxiter,preconditioner) } x[,i] = tmpres$x iter[i] = tmpres$iter errors1[[i]] = tmpres$errors1 errors2[[i]] = tmpres$errors2 if (verbose){ message(paste("* lsolve.bicg : B's column.",i,"being processed..")) } } res = list("x"=x,"iter"=iter,"errors1"=errors1,"errors2"=errors2) } ########################################################################### # Step 3. Finalize if ("flag" %in% names(res)){ flagval = res$flag if (flagval==0){ if (verbose){ message("* lsolve.bicg : convergence well achieved.") } } else if (flagval==1){ if (verbose){ message("* lsolve.bicg : convergence not achieved within maxiter.") } } else { if (verbose){ message("* lsolve.bicg : breakdown.") } } } if (verbose){ message("* lsolve.bicg : computations finished.") } return(res) } Rlinsolve/R/aux_FISCH.R0000644000176200001440000000414214110077625014270 0ustar liggesusers#' Generate a 2-dimensional discrete Poisson matrix #' #' Poisson equation is one of most well-known elliptic partial differential equations. In order to #' give a concrete example, a discrete Poisson matrix is generated, assuming we have \code{N} number of #' grid points for each dimension under square domain. \emph{fisch} is a German word for Poisson. #' #' @param N the number of grid points for each direction. #' @param sparse a logical; \code{TRUE} for returning sparse matrix, \code{FALSE} otherwise. #' #' @return an \eqn{(N^2 \times N^2)} matrix having block banded structure. #' @examples #' ## generate dense and sparse Poisson matrix of size 25 by 25. #' A = aux.fisch(5, sparse=FALSE) #' B = aux.fisch(5, sparse=TRUE) #' (all(A==B)) # TRUE if two matrices are equal. #' #' #' @references Golub, G. H. and Van Loan, C. F. (1996) \emph{Matrix Computations, 3rd Ed.}, pages 177–180. #' @rdname aux_FISCH #' @export aux.fisch <- function(N,sparse=FALSE){ if ((!is.numeric(N))||(is.na(N))||(is.infinite(N))||(length(N)>1)||(N<=2)){ stop("* aux.fisch : an input 'N' should be a positive integer larger than 2.") } if (!is.logical(sparse)){ stop("* aux.fisch : 'sparse' is a logical flag.") } siz = as.integer(N) leng = siz*siz; dia = matrix(0,nrow=siz,ncol=siz) diag(dia) = 4; for (i in 1:(siz-1)){ dia[i,i+1] = -1; dia[i+1,i] = -1; } if (sparse){ mat = Matrix(0,nrow=leng,ncol=leng) } else { mat = matrix(0,nrow=leng,ncol=leng) } if (!sparse){ for (ib in 1:siz){ mat[(1+(ib-1)*siz):(ib*siz),(1+(ib-1)*siz):(ib*siz)] = dia } for (ib in 1:(siz-1)){ mat[(1+(ib-1)*siz):(ib*siz),(1+ib*siz):((ib+1)*siz)] = -diag(siz) mat[(1+ib*siz):((ib+1)*siz),(1+(ib-1)*siz):(ib*siz)] = -diag(siz) } } else { dia = Matrix(dia,sparse=TRUE) off = Matrix(-diag(siz),sparse=TRUE) for (ib in 1:siz){ mat[(1+(ib-1)*siz):(ib*siz),(1+(ib-1)*siz):(ib*siz)] = dia } for (ib in 1:(siz-1)){ mat[(1+(ib-1)*siz):(ib*siz),(1+ib*siz):((ib+1)*siz)] = off mat[(1+ib*siz):((ib+1)*siz),(1+(ib-1)*siz):(ib*siz)] = off } } return(mat) } Rlinsolve/R/auxiliary.R0000644000176200001440000000301014110077625014557 0ustar liggesusers # Auxiliary Functions ----------------------------------------------------- # Aux 1:: aux.is.dd(w/ doc) : check if diagonally dominant # Aux 2:: aux.is.psd : check positive semidefinite # Aux 3:: aux.is.sparse : sparseformats = c("dgCMatrix","dtCMatrix","dsCMatrix") # ----------------------------------------------------------------------- # Aux 3:: aux.is.sparse : check whether one of the following #' @keywords internal #' @noRd aux.is.sparse <- function(AA){ sparseformats = c("dgCMatrix","dtCMatrix","dsCMatrix") for (i in 1:3){ if (inherits(AA, sparseformats[i])){ return(TRUE) } } return(FALSE) } # ------------------------------------------------------------------------ # Aux 1:: aux.is.dd # "sdd" : strictly # "wdd" : weakly # FALSE : not at all #' @keywords internal #' @noRd aux.is.dd <- function(A){ absA = abs(A) # 1-1. separate terms diagA = 2*(diag(absA)) offdA = colSums(absA) # 1-2. logic if (all(diagA>offdA)){ res = "sdd" } else if ((all(diagA>=offdA))&&(any(diagA==offdA))){ res = "wdd" } else { res = FALSE } return(res) } # ------------------------------------------------------------------------ # Aux 2:: aux.is.psd #' Positive Semidefiniteness #' PD, PSD, or FALSE #' #' @keywords internal #' @noRd aux.is.psd <- function(A){ # get eigenvalues eigs = eigen(A, only.values = TRUE) # PD, PSD, or FALSE if (all(eigs>0)){res = "PD"} else if ((all(eigs>=0))&&(any(eigs>0))){res = "PSD"} else {res = FALSE} # finalize return(res) } Rlinsolve/NEWS.md0000644000176200001440000000035114110100253013307 0ustar liggesusers# Rlinsolve 0.3.2 * Fixed CRAN error. # Rlinsolve 0.3.1 * Added a `NEWS.md` file to track changes to the package. * Partial support for bigmemory is dropped due to its instability. We expect it to be running smooth in the future. Rlinsolve/MD50000644000176200001440000000471114110217132012532 0ustar liggesusers722a80fff930a0276ddd887772e68f6f *DESCRIPTION ce29a8a7f56b9241c73f75cffc335688 *LICENSE e942b3185571401e268bcaf4ea119b1d *NAMESPACE 094baef125212d12d06cf03dbe390336 *NEWS.md 953f1e642fe00ea59bdd78c2332fa53d *R/RcppExports.R d0f9453a84225e4a8c027dde506decd4 *R/aux_FISCH.R 650525c31ab3a1065674dc6a1cbc806b *R/auxiliary.R fcb500af1550ff2978ba659dfed54f35 *R/init.R 87e25103f290a404090284537333475b *R/lsolve_BICG.R 302b994507af65415a971985b45991e1 *R/lsolve_BICGSTAB.R beac083197f7e24303f59ff6887e45e8 *R/lsolve_CG.R f83478fcb9b33e6bcc2613b4219611a0 *R/lsolve_CGS.R 25622805fadb9bb9443f2c28ba8dfd82 *R/lsolve_CHEBY.R dff32739bad9b5470630174a5ba87ba0 *R/lsolve_GMRES.R d2cccc4320f0362c69f5acfb606f41be *R/lsolve_GS.R 9c0455b7f77e2afddd5557e9a183077d *R/lsolve_JACOBI.R 275104219aaf8395a5133dfe806ae64b *R/lsolve_QMR.R 314b8be17d1fcdce9db7627df883a409 *R/lsolve_SOR.R d021552e7ce0eb2fe8fcff074cbc0ab7 *R/lsolve_SSOR.R 62779a9cdd6e69e3943cb99d7e2c5415 *R/package-Rlinsolve.R 37b7e68148ee2672f749f409ee54021e *build/partial.rdb e6e8d3e61ab65e139ede34439c4eed61 *inst/REFERENCES.bib a0617b485daa8a71f934920754326636 *man/Rlinsolve.Rd ad9babbfc5cd9cf61eac9d06429058ee *man/aux_FISCH.Rd 826e19a3f67afc8f1b8099d9828dddae *man/basic_GS.Rd 8e1586459aab26b3c33a987c60e3f3cb *man/basic_JACOBI.Rd d850d0a625f059d543eec901b02e86d0 *man/basic_SOR.Rd d744580fae955cec75d2a5aa865ffc27 *man/basic_SSOR.Rd 7264e10ac9bcfd0dfd49b6f2ccb5fcb4 *man/krylov_BICG.Rd cc629bf48c4d10fa3d6a85d7d1ea416d *man/krylov_BICGSTAB.Rd 0d5eb25648cfad3b362270649896758d *man/krylov_CG.Rd 753428399e59909143bd712ef52b0ff2 *man/krylov_CGS.Rd acf152a54006a5e80930ce8b45316f84 *man/krylov_CHEBY.Rd 96b40bf7ccb6093aebc53381c1858411 *man/krylov_GMRES.Rd 1612089af935fbc0e0b102ea21bb48cc *man/krylov_QMR.Rd 77b069f362885302f16e22f781c34811 *src/Makevars 77b069f362885302f16e22f781c34811 *src/Makevars.win 9b3fb667c85e6edc09ce812d5336119a *src/RcppExports.cpp 326877fa2f968e84545e00fcb163d0d3 *src/krylov_bicg.cpp 9038677d6748820797effdbf7cab69ea *src/krylov_bicgstab.cpp f2b1b024bd444a6e206c962ea58495e8 *src/krylov_cg.cpp 4b951d31e89d6fa86232cbf8674acdf5 *src/krylov_cgs.cpp 321a691071cf9ea8f620398f7f31931d *src/krylov_cheby.cpp b3c50abfc3a291682c7aee08d860c66d *src/krylov_gmres.cpp 68291696e0455ea485e789a46a4edc86 *src/krylov_qmr.cpp bba99f47273b068366124414d85593e4 *src/method_gs.cpp fa811b26c2d34362b3c1213c659fee76 *src/method_jacobi.cpp 036834ba825fd3fd8b8c979b18515cca *src/method_sor.cpp 19fce4365b786e03c1d3af402b39dd9e *src/method_ssor.cpp Rlinsolve/inst/0000755000176200001440000000000014110077625013207 5ustar liggesusersRlinsolve/inst/REFERENCES.bib0000644000176200001440000000734514110100203015272 0ustar liggesusers @incollection{watson_conjugate_1976, address = {Berlin, Heidelberg}, title = {Conjugate gradient methods for indefinite systems}, volume = {506}, isbn = {978-3-540-07610-0 978-3-540-38129-7}, booktitle = {Numerical {Analysis}}, publisher = {Springer Berlin Heidelberg}, author = {Fletcher, R.}, editor = {Watson, G. Alistair}, year = {1976}, pages = {73--89} } @article{voevodin_question_1983, title = {The question of non-self-adjoint extension of the conjugate gradients method is closed}, volume = {23}, issn = {00415553}, language = {en}, number = {2}, journal = {USSR Computational Mathematics and Mathematical Physics}, author = {Voevodin, V.V.}, month = jan, year = {1983}, pages = {143--144}, file = {[Voevodin.1983] The question of non-self-adjoint extension of the conjugate gradients method is.pdf:/home/kisung/Dropbox/V2. Applied Mathematics/P2. Numerical/S3. linsolve/[Voevodin.1983] The question of non-self-adjoint extension of the conjugate gradients method is.pdf:application/pdf} } @article{van_der_vorst_bi-cgstab:_1992, title = {Bi-{CGSTAB}: {A} {Fast} and {Smoothly} {Converging} {Variant} of {Bi}-{CG} for the {Solution} of {Nonsymmetric} {Linear} {Systems}}, volume = {13}, issn = {0196-5204, 2168-3417}, shorttitle = {Bi-{CGSTAB}}, language = {en}, number = {2}, journal = {SIAM Journal on Scientific and Statistical Computing}, author = {van der Vorst, H. A.}, month = mar, year = {1992}, pages = {631--644} } @book{saad_iterative_2003, address = {Philadelphia}, edition = {2nd ed}, title = {Iterative methods for sparse linear systems}, isbn = {978-0-89871-534-7}, publisher = {SIAM}, author = {Saad, Y.}, year = {2003}, keywords = {Differential equations, Partial, Iterative methods (Mathematics), Numerical solutions, Sparse matrices} } @article{hestenes_methods_1952, title = {Methods of conjugate gradients for solving linear systems}, volume = {49}, issn = {0091-0635}, language = {en}, number = {6}, journal = {Journal of Research of the National Bureau of Standards}, author = {Hestenes, M.R. and Stiefel, E.}, month = dec, year = {1952}, pages = {409} } @article{sonneveld_cgs_1989, title = {{CGS}, {A} {Fast} {Lanczos}-{Type} {Solver} for {Nonsymmetric} {Linear} systems}, volume = {10}, issn = {0196-5204, 2168-3417}, language = {en}, number = {1}, journal = {SIAM Journal on Scientific and Statistical Computing}, author = {Sonneveld, Peter}, month = jan, year = {1989}, pages = {36--52} } @article{gutknecht_chebyshev_2002, title = {The {Chebyshev} iteration revisited}, volume = {28}, issn = {01678191}, language = {en}, number = {2}, journal = {Parallel Computing}, author = {Gutknecht, Martin H. and Röllin, Stefan}, month = feb, year = {2002}, pages = {263--283} } @article{saad_gmres:_1986, title = {{GMRES}: {A} {Generalized} {Minimal} {Residual} {Algorithm} for {Solving} {Nonsymmetric} {Linear} {Systems}}, volume = {7}, issn = {0196-5204, 2168-3417}, shorttitle = {{GMRES}}, language = {en}, number = {3}, journal = {SIAM Journal on Scientific and Statistical Computing}, author = {Saad, Youcef and Schultz, Martin H.}, month = jul, year = {1986}, pages = {856--869} } @book{demmel_applied_1997, title = {Applied {Numerical} {Linear} {Algebra}}, isbn = {978-0-89871-389-3 978-1-61197-144-6}, language = {en}, publisher = {Society for Industrial and Applied Mathematics}, author = {Demmel, James W.}, month = jan, year = {1997} } @article{freund_qmr:_1991, title = {{QMR}: a quasi-minimal residual method for non-{Hermitian} linear systems}, volume = {60}, issn = {0029-599X, 0945-3245}, language = {en}, number = {1}, journal = {Numerische Mathematik}, author = {Freund, Roland W. and Nachtigal, No�l M.}, month = dec, year = {1991}, pages = {315--339} }