diag_op: Diagonal-vector operation on an HDF5Matrix

View source: R/S3_diagonal.R

diag_opR Documentation

Diagonal-vector operation on an HDF5Matrix

Description

Applies an element-wise binary operation between an HDF5Matrix and a diagonal vector (a 1-row or 1-column HDF5Matrix). The vector is broadcast across each row of the matrix.

The standard arithmetic operators (+, -, *, /) dispatch automatically to this function when one operand is a 1-row or 1-column HDF5Matrix.

Usage

diag_op(x, diag, op = "+", ...)

## S3 method for class 'HDF5Matrix'
diag_op(x, diag, op = "+", outgroup = NULL, outdataset = NULL, ...)

Arguments

x

An HDF5Matrix (matrix, m \times n).

diag

An HDF5Matrix with one row or one column.

op

Character. One of "+", "-", "*", "/".

...

Additional arguments passed to x$diag_op(): outgroup, outdataset, overwrite, threads, compression.

outgroup

Character or NULL. HDF5 group where the result is stored. Default "OUTPUT".

outdataset

Character or NULL. Dataset name for the result.

Value

A new HDF5Matrix.

See Also

diag_scale

Examples


tmp <- tempfile(fileext = ".h5")
M   <- hdf5_create_matrix(tmp, "data/M", data = matrix(rnorm(10000), 100, 100))
d   <- hdf5_create_matrix(tmp, "data/d", data = matrix(rnorm(10000), 100, 100))
R1  <- diag_op(M, d, "*")    # scale each column
R2  <- M * d                  # same via operator auto-dispatch
hdf5_close_all()
unlink(tmp)



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