addDiagonals
C++ Function Reference
1 Signature
void BigDataStatMeth::DiagonalOps::addDiagonals(BigDataStatMeth::hdf5Dataset *dsA, BigDataStatMeth::hdf5Dataset *dsB, BigDataStatMeth::hdf5Dataset *dsResult, std::string target="new", bool bparal=false, Rcpp::Nullable< int > threads=R_NilValue)2 Description
Add diagonal elements from two matrices or vectors.
3 Parameters
dsA(BigDataStatMeth::hdf5Dataset *): First input dataset (matrix or vector)dsB(BigDataStatMeth::hdf5Dataset *): Second input dataset (matrix or vector)dsResult(BigDataStatMeth::hdf5Dataset *): Result dataset (only used if target=“new”)target(std::string): Where to write result: “A”, “B”, or “new”bparal(bool): Whether to use parallel processingthreads(Rcpp::Nullable< int >): Number of threads for parallel processing
4 Details
Performs optimized diagonal addition C_diag = A_diag + B_diag. Automatically detects whether inputs are matrices (extracts diagonals) or vectors (direct vector operation). Uses vectorOperations.hpp for maximum efficiency.
5 Call Graph
6 Source Code
NoteImplementation
File: inst/include/hdf5Utilities/hdf5DiagonalMethods.hpp • Lines 386-411
inline void addDiagonals(BigDataStatMeth::hdf5Dataset* dsA, BigDataStatMeth::hdf5Dataset* dsB,
BigDataStatMeth::hdf5Dataset* dsResult, std::string target = "new",
bool bparal = false, Rcpp::Nullable<int> threads = R_NilValue)
{
try {
bool isVectorA = isDiagonalVector(dsA);
bool isVectorB = isDiagonalVector(dsB);
Rcpp::Rcout<<"\n Error add-1";
if (isVectorA && isVectorB && (target == "A" || target == "B")) {
Rcpp::Rcout<<"\n Error add-2";
BigDataStatMeth::hdf5Dataset* targetDataset = (target == "A") ? dsA : dsB;
Rcpp::Rcout<<"\n Error add-3";
Rcpp_vector_add_hdf5(dsA, dsB, targetDataset, bparal, threads);
} else if (isVectorA && isVectorB && target == "new") {
Rcpp::Rcout<<"\n Error add-4";
Rcpp_vector_add_hdf5(dsA, dsB, dsResult, bparal, threads);
} else {
Rcpp::Rcout<<"\n Error add-5";
performMatrixDiagonalOperation(dsA, dsB, dsResult, 0, target, bparal, threads);
}
Rcpp::Rcout<<"\n Error add-6";
} catch(std::exception& ex) {
Rf_error("Error in addDiagonals: %s", ex.what());
}
}7 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = addDiagonals(...);