getMatrixBlockSize

C++ Function Reference

1 Signature

std::vector< hsize_t > BigDataStatMeth::getMatrixBlockSize(int nrows, int ncols)

2 Description

Calculates optimal block size for matrix operations.

3 Parameters

  • nrows (int): Number of rows
  • ncols (int): Number of columns

4 Returns

std::vector Vector containing optimized dimensions

5 Details

nrowsNumber of rows ncolsNumber of columns std::vector Vector containing optimized dimensions Particularly useful for:Omics data with few samples and many variablesMemory-efficient processing of rectangular matricesOptimizing I/O operations

6 Caller Graph

Function dependencies

7 Source Code

File: inst/include/Utilities/Utilities.hppLines 338-379

inline std::vector<hsize_t> getMatrixBlockSize( int nrows, int ncols ) 
    {
        size_t  maxRows = nrows,
                maxCols = ncols;
        
        std::vector<hsize_t> blockSize = {0, 0};
        
        try
        {
            // Calculem el mínim de files
            if( nrows < ncols ) {
                if( maxRows < MAXBLOCKSIZE ){
                    maxRows = nrows;
                } else{
                    maxRows = MAXBLOCKSIZE;
                }
                
                maxCols = std::floor( MAXELEMSINBLOCK / maxRows );
                if( maxCols> (unsigned)ncols || maxCols + 1 == (unsigned)ncols) {
                    maxCols = ncols;
                }
            } else {
                if( maxCols < MAXBLOCKSIZE ){
                    maxCols = ncols;
                } else{
                    maxCols = MAXBLOCKSIZE;
                }
                maxRows = std::floor( MAXELEMSINBLOCK / maxCols );
                if( maxRows> (unsigned)nrows || maxRows + 1 == (unsigned)nrows) {
                    maxRows = nrows;
                }
                
            }    
            blockSize[0] = maxRows;
            blockSize[1] = maxCols;
            
        } catch(std::exception& ex) {
            Rcpp::Rcout<< "c++ exception getMatrixBlockSize: "<<ex.what()<< " \n";
        }
        
        return(blockSize);
    }

8 Usage Example

#include "BigDataStatMeth.hpp"

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