RcppSolve
C++ Function Reference
1 Signature
Eigen::MatrixXd BigDataStatMeth::RcppSolve(Eigen::Map< Eigen::MatrixXd > a, Eigen::Map< Eigen::MatrixXd > b)2 Description
Solves the linear system AX = B using Eigen matrices.
3 Parameters
a(Eigen::Map< Eigen::MatrixXd >): Input matrix A (coefficient matrix)b(Eigen::Map< Eigen::MatrixXd >): Input/output matrix B (right-hand side matrix, will contain solution X)
4 Returns
Eigen::MatrixXd Solution matrix X
5 Details
aInput matrix A (coefficient matrix) bInput/output matrix B (right-hand side matrix, will contain solution X) Eigen::MatrixXd Solution matrix X This function automatically detects if A is symmetric and uses the appropriate LAPACK solver (DSYSV for symmetric, DGESV for general matrices). The solution is computed in-place in matrix b.
6 Call Graph
7 Source Code
NoteImplementation
File: inst/include/hdf5Algebra/matrixEquationSolver.hpp • Lines 89-124
inline Eigen::MatrixXd RcppSolve(Eigen::Map<Eigen::MatrixXd> a, Eigen::Map<Eigen::MatrixXd> b)
{
try {
char Uchar = 'U';
int info = 0;
// Declare matrix variables
int n = a.rows();
int nrhs = b.cols();
int lwork = std::max( 1, n );
int lda = std::max( 1, n );
int ldb = std::max( 1, n );
std::vector<int> ipiv(n);
std::vector<double> work(lwork);
// Solve matrix equation
if( a == a.transpose() )
{
// dsysv_( char* UPLO, int* N , int* NRHS, double* A, int* LDA, int* IPIV, double* B, int* LDB, double* WORK, int* LWORK, int* INFO);
dsysv_( &Uchar, &n, &nrhs, a.data(), &lda, ipiv.data(), b.data(), &ldb, work.data(), &lwork, &info);
} else {
// dgesv( int N, int NRHS, double A, int LDA, int IPIV, double B, int LDB, int INFO);
dgesv_( &n, &nrhs, a.data(), &lda, ipiv.data(), b.data(), &ldb, &info );
}
} catch(std::exception &ex) {
Rcpp::Rcout<< ex.what();
return(Eigen::MatrixXd::Zero(2,2));
}
return(b);
}8 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = RcppSolve(...);