Learn R Programming

BigDataStatMeth (version 1.0.3)

bdDiag_scalar_hdf5: Apply Scalar Operations to Diagonal Elements

Description

Performs optimized scalar operations on diagonal elements of matrices or vectors stored in HDF5 format. Automatically detects whether input is a matrix (extracts diagonal) or vector (direct operation) and applies the specified scalar operation.

Usage

bdDiag_scalar_hdf5(
  filename,
  group,
  dataset,
  scalar,
  operation,
  target = NULL,
  paral = NULL,
  threads = NULL,
  outgroup = NULL,
  outdataset = NULL,
  overwrite = NULL
)

Value

List with components:

fn

Character string with the HDF5 filename

gr

Character string with the HDF5 group

ds

Character string with the full dataset path (group/dataset)

Arguments

filename

String. Path to the HDF5 file containing the dataset.

group

String. Group path containing the input dataset.

dataset

String. Name of the input dataset (matrix or vector).

scalar

Numeric. Scalar value for the operation.

operation

String. Operation to perform: "add", "subtract", "multiply", "divide".

target

Optional string. Where to write result: "input" or "new" (default: "new").

paral

Optional logical. Whether to use parallel processing (default: FALSE).

threads

Optional integer. Number of threads for parallel processing.

outgroup

Optional string. Output group path (only used if target="new").

outdataset

Optional string. Output dataset name (only used if target="new").

overwrite

Optional logical. Whether to overwrite existing datasets (default: FALSE).

Details

This function provides flexible scalar operations on diagonals:

  • Supported operations:

    • "+": diagonal[i] + scalar

    • "-": diagonal[i] - scalar

    • "*": diagonal[i] * scalar

    • "/": diagonal[i] / scalar

    • "pow": diagonal[i] ^ scalar

  • Input types:

    • Matrix input: Extracts diagonal automatically

    • Vector input: Operates directly (most efficient)

  • Target options:

    • "input": Modifies original dataset in-place

    • "new": Creates new dataset with result

Examples

Run this code
if (FALSE) {
library(BigDataStatMeth)

# Create test matrix
A <- matrix(rnorm(100), 10, 10)
bdCreate_hdf5_matrix("test.h5", A, "data", "matrix_A", overwriteFile = TRUE)

# Add scalar to diagonal (creates new dataset)
result <- bdDiag_scalar_hdf5("test.h5", "data", "matrix_A",
                            scalar = 5.0, operation = "+",
                            target = "new", outdataset = "diag_plus_5")

# Multiply diagonal in-place
result2 <- bdDiag_scalar_hdf5("test.h5", "data", "matrix_A", 
                             scalar = 2.0, operation = "*",
                             target = "input")
}

Run the code above in your browser using DataLab