get_HDF5_rowMins
C++ Function Reference
1 Signature
Eigen::VectorXd BigDataStatMeth::get_HDF5_rowMins(BigDataStatMeth::hdf5Dataset *dsA, bool bparal, Rcpp::Nullable< int > wsize, Rcpp::Nullable< int > threads)2 Description
Row minimums of an HDF5 matrix (block-wise, parallel).
3 Parameters
dsA(BigDataStatMeth::hdf5Dataset *): Open HDF5 dataset.bparal(bool): Enable OpenMP parallelism.wsize(Rcpp::Nullable< int >): Block size (NULL = auto).threads(Rcpp::Nullable< int >): Thread count (NULL = auto).
4 Returns
Vector of length nrows_R.
5 Details
Equivalent to apply(X, 1, min).
6 Call Graph
7 Source Code
NoteImplementation
File: inst/include/hdf5Algebra/matrixAggregations.hpp • Lines 645-704
inline Eigen::VectorXd get_HDF5_rowMins(BigDataStatMeth::hdf5Dataset* dsA,
bool bparal,
Rcpp::Nullable<int> wsize,
Rcpp::Nullable<int> threads)
{
try {
const hsize_t nHDF5rows = dsA->nrows();
const hsize_t nHDF5cols = dsA->ncols();
const hsize_t bs = agg_block_size(wsize, nHDF5cols, nHDF5rows);
std::vector<hsize_t> starts, sizes;
agg_make_blocks(nHDF5cols, bs, starts, sizes);
const std::vector<hsize_t> stride = {1, 1}, blk = {1, 1};
const int nthreads = static_cast<int>(
BigDataStatMeth::get_threads(bparal, threads));
Eigen::VectorXd result =
Eigen::VectorXd::Constant(nHDF5cols,
std::numeric_limits<double>::infinity());
#pragma omp parallel for schedule(dynamic) num_threads(nthreads) \
shared(dsA, starts, sizes, result)
for (hsize_t bi = 0; bi < starts.size(); bi++) {
std::vector<double> vd(nHDF5rows * sizes[bi]);
//.. 20260325 - remove critical ..// #pragma omp critical(accessFile)
//.. 20260325 - remove critical ..// {
dsA->readDatasetBlock({0, starts[bi]}, {nHDF5rows, sizes[bi]}, stride, blk, vd.data());
//.. 20260325 - remove critical ..// }
Eigen::Map<const RMMatd> X(vd.data(),
static_cast<Eigen::Index>(nHDF5rows),
static_cast<Eigen::Index>(sizes[bi]));
// colwise min: compares across ncols_R (HDF5 rows), one min per R-row
Eigen::RowVectorXd block_mins = X.colwise().minCoeff();
// Take element-wise min with running result to handle multi-block case
// (This case only occurs when ncols_R > 1 block, which shouldn't
// happen for row-wise iteration where ncols_R is the fixed dim.
// But defensive code here for correctness.)
for (hsize_t k = 0; k < sizes[bi]; k++) {
result[starts[bi] + k] = std::min(result[starts[bi] + k],
block_mins[k]);
}
}
return result;
} catch (H5::FileIException& e) {
throw std::runtime_error("c++ exception get_HDF5_rowMins (File IException): "
+ std::string(e.getDetailMsg()));
} catch (H5::DataSetIException& e) {
throw std::runtime_error("c++ exception get_HDF5_rowMins (DataSet IException): "
+ std::string(e.getDetailMsg()));
} catch (std::exception& e) {
throw std::runtime_error(std::string("c++ exception get_HDF5_rowMins: ")
+ e.what());
}
}8 Usage Example
#include "BigDataStatMeth.hpp"
// Example usage
auto result = get_HDF5_rowMins(...);