subtractDiagonals

C++ Function Reference

1 Signature

void BigDataStatMeth::DiagonalOps::subtractDiagonals(BigDataStatMeth::hdf5Dataset *dsA, BigDataStatMeth::hdf5Dataset *dsB, BigDataStatMeth::hdf5Dataset *dsResult, std::string target="new", bool bparal=false, Rcpp::Nullable< int > threads=R_NilValue)

2 Description

Subtract diagonal elements from two matrices or vectors.

3 Parameters

  • dsA (BigDataStatMeth::hdf5Dataset *): First input dataset (minuend)
  • dsB (BigDataStatMeth::hdf5Dataset *): Second input dataset (subtrahend)
  • dsResult (BigDataStatMeth::hdf5Dataset *): Result dataset (will be created)
  • target (std::string): Where to write result: “A”, “B”, or “new”
  • bparal (bool): Whether to use parallel processing
  • threads (Rcpp::Nullable< int >): Number of threads for parallel processing

4 Details

Performs optimized diagonal subtraction C_diag = A_diag - B_diag. Same optimization strategy as addDiagonals but for subtraction operation.

5 Call Graph

Function dependencies

6 Source Code

File: inst/include/hdf5Utilities/hdf5DiagonalMethods.hppLines 443-467

inline void subtractDiagonals(BigDataStatMeth::hdf5Dataset* dsA, BigDataStatMeth::hdf5Dataset* dsB,
                                      BigDataStatMeth::hdf5Dataset* dsResult, std::string target = "new",
                                      bool bparal = false, Rcpp::Nullable<int> threads = R_NilValue)
        {
            BigDataStatMeth::hdf5Dataset* targetDataset = nullptr;

            try {
    
                bool isVectorA = isDiagonalVector(dsA);
                bool isVectorB = isDiagonalVector(dsB);
                
                if (isVectorA && isVectorB && (target == "A" || target == "B")) {
                    targetDataset = (target == "A") ? dsA : dsB;
                    Rcpp_vector_subtract_hdf5(dsA, dsB, targetDataset, bparal, threads);
                    // delete targetDataset; targetDataset = nullptr;
                } else if (isVectorA && isVectorB && target == "new") {
                    Rcpp_vector_subtract_hdf5(dsA, dsB, dsResult, bparal, threads);
                } else {
                    performMatrixDiagonalOperation(dsA, dsB, dsResult, 1, target, bparal, threads);
                }
            } catch(std::exception& ex) {
                checkClose_file(targetDataset);
                throw std::runtime_error(std::string("Error in subtractDiagonals: ") + ex.what());
            }
        }

7 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = subtractDiagonals(...);