Ops.HDF5Matrix: Elementwise arithmetic operators for HDF5Matrix objects

View source: R/S3_diagonal.R View source: R/S3_arithmetic.R

Ops.HDF5MatrixR Documentation

Elementwise arithmetic operators for HDF5Matrix objects

Description

Standard R arithmetic operators applied element-wise to HDF5Matrix objects stored on disk. Both operands must be HDF5Matrix objects with identical dimensions.

Usage

## S3 method for class 'HDF5Matrix'
Ops(e1, e2)

Arguments

e1

An HDF5Matrix object (left-hand side)

e2

An HDF5Matrix object (right-hand side)

Details

Supported operators:

+

Element-wise addition

-

Element-wise subtraction

*

Element-wise multiplication (Hadamard product)

/

Element-wise division. Division by zero produces NaN or Inf, matching base R behaviour.

All operations use block-wise processing and optional OpenMP parallelisation, controlled via hdf5matrix_options.

Performance settings:

Global options set via hdf5matrix_options are applied. For explicit control use the R6 methods directly: A$add(B, paral = TRUE, threads = 4).

Value

A new HDF5Matrix containing the result, stored in the same HDF5 file as e1 under a temporary dataset name.

See Also

hdf5matrix_options for global performance settings, HDF5Matrix for R6 methods with explicit parameters

Examples


fn <- tempfile(fileext = ".h5")
A_hdf5 <- hdf5_create_matrix(fn, "data/A", data = matrix(1:12, 3, 4))
B_hdf5 <- hdf5_create_matrix(fn, "data/B", data = matrix(2, 3, 4))

C <- A_hdf5 + B_hdf5
D <- A_hdf5 - B_hdf5
E <- A_hdf5 * B_hdf5
G <- A_hdf5 / B_hdf5

all.equal(as.matrix(C), matrix(1:12, 3, 4) + 2)

hdf5_close_all()
unlink(fn)



BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.