reduce: Reduce a group of HDF5 datasets by accumulation (generic)

View source: R/S3_operations.R

reduceR Documentation

Reduce a group of HDF5 datasets by accumulation (generic)

Description

Generic S3 function for reducing (accumulating) all datasets in the same HDF5 group as x into a single dataset using a binary operation ("+" or "-").

This function operates on the group that contains x, not on the matrix data of x itself. All datasets in the group must have the same dimensions.

Usage

reduce(x, ...)

Arguments

x

An HDF5Matrix.

...

Additional arguments forwarded to the method.

Details

Two access patterns are available:

  • reduce(x, ...) — use when you already have an HDF5Matrix object open. Operates on all datasets in its group.

  • hdf5_reduce(filename, group, ...) — use when you only have the file path and group name, without needing to open an object.

This separation mirrors the pattern used by packages such as DBI/RSQLite (connection object vs. file path access).

Note: this is not a row- or column-wise reduction (use colSums(), rowMeans(), etc. for those). It accumulates entire datasets element-wise.

Value

A new HDF5Matrix containing the accumulated result.

See Also

hdf5_reduce for the standalone group-level version.

Examples


fn <- tempfile(fileext = ".h5")

# Create three matrices in the same group
hdf5_create_matrix(fn, "partials/chunk_0", data = matrix(1:100, 10, 10))
hdf5_create_matrix(fn, "partials/chunk_1", data = matrix(1:100, 10, 10))
hdf5_create_matrix(fn, "partials/chunk_2", data = matrix(1:100, 10, 10))

# Open one as entry point — reduce() operates on its whole group
partial <- hdf5_matrix(fn, "partials/chunk_0")
total   <- reduce(partial, func = "+")
dim(total)

hdf5_close_all()
unlink(fn)



BigDataStatMeth documentation built on June 8, 2026, 5:07 p.m.