Learn R Programming

BigDataStatMeth (version 2.0.3)

diag_op: 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 HDF5Matrix diag_op(x, diag, op = "+", outgroup = NULL, outdataset = NULL, ...)

Value

A new HDF5Matrix.

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.

See Also

diag_scale

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab