Rcpp_matrix_sum
C++ Function Reference
1 Signature
Rcpp::RObject BigDataStatMeth::Rcpp_matrix_sum(T A, T B)2 Description
Low-level block-based matrix-vector addition implementation.
3 Parameters
A(T): Input matrixB(T): Input vectorblock_size(``): Size of processing blocksbparal(``): Enable/disable parallel processingthreads(``): Number of threads for parallel computation
4 Returns
Eigen::MatrixXd containing the result
5 Details
Core implementation that:Processes matrix in cache-friendly blocksSupports parallel execution through OpenMPOptimizes memory access patternsHandles edge cases for non-uniform block sizes
6 Source Code
NoteImplementation
File: inst/include/memAlgebra/memSum.hpp • Lines 91-115
inline Rcpp::RObject Rcpp_matrix_sum ( T A, T B)
{
// static_assert(std::is_same<T, Eigen::MatrixXd >::value ||
// std::is_same<T, Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> >::value ||
// std::is_same<T, Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>> >::value ||
// std::is_same<T, Rcpp::NumericMatrix >::value,
// "Error - type not allowed");
Rcpp::NumericMatrix m = Rcpp::as<Rcpp::NumericMatrix>(A);
Rcpp::NumericMatrix m2 = Rcpp::as<Rcpp::NumericMatrix>(B);
if( m.rows() == m2.rows() && m.cols() == m2.cols()) {
Rcpp::NumericVector C = m + m2;
C.attr("dim") = Rcpp::Dimension( m.rows(), m.cols());
return(C);
} else {
Rcpp::Rcout<<"Error: non-conformable arguments";
}
return(R_NilValue);
}7 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = Rcpp_matrix_sum(...);