hdf5DiagonalMatrix

C++ Class Reference

1 Overview

Add diagonal elements from two matrices or vectors.

2 Detailed Description

Performs optimized diagonal addition C_diag = A_diag + B_diag. Automatically detects whether inputs are matrices (extracts diagonals) or vectors (direct vector operation). Uses vectorOperations.hpp for maximum efficiency.

3 Class Hierarchy

Class diagram

4 Inheritance

Inherits from:

  • BigDataStatMeth::hdf5Dataset

5 Public Interface

5.1 Methods

5.1.1 hdf5DiagonalMatrix()

BigDataStatMeth::hdf5DiagonalMatrix::hdf5DiagonalMatrix(BigDataStatMeth::hdf5File *oFile, std::string group, std::string datasetname, bool overwrite)

Constructor with file object.

Parameters:

  • oFile (BigDataStatMeth::hdf5File *): HDF5 file object
  • group (std::string): Group path
  • datasetname (std::string): Dataset name
  • overwrite (bool): Whether to overwrite existing dataset

oFileHDF5 file object groupGroup path datasetnameDataset name overwriteWhether to overwrite existing dataset


5.1.2 createScalarDiagonalMatrix()

void BigDataStatMeth::hdf5DiagonalMatrix::createScalarDiagonalMatrix(hsize_t size, double scalar, const std::vector< double > &diagonal_vector, hsize_t block_size_hint=1024, int compression_level=6, Rcpp::Nullable< int > threads=R_NilValue, std::string output_type="matrix")

Create diagonal matrix with scalar multiplication.

Parameters:

  • size (hsize_t): Size of the diagonal (N elements)
  • scalar (double): Scalar to multiply with diagonal vector
  • diagonal_vector (const std::vector< double > &): Vector of diagonal values (length = size)
  • block_size_hint (hsize_t): Suggested block size for processing (default: 1024)
  • compression_level (int): Compression level (0-9, default: 6)
  • threads (Rcpp::Nullable< int >): Number of threads to use (default: auto-detect)
  • output_type (std::string): Output format: “matrix” for N×N sparse matrix, “vector” for 1×N vector (default: “matrix”)

Creates a diagonal matrix where diagonal elements are scalar * vector[i]. Uses optimized block-wise processing that only processes diagonal blocks, resulting in ~250x reduction in I/O operations compared to full matrix processing.


5.1.3 createScalarIdentityMatrix()

void BigDataStatMeth::hdf5DiagonalMatrix::createScalarIdentityMatrix(hsize_t size, double scalar, hsize_t block_size_hint=1024, int compression_level=6, Rcpp::Nullable< int > threads=R_NilValue, std::string output_type="matrix")

Create identity matrix scaled by scalar with flexible output format.

Parameters:

  • size (hsize_t): Size of the identity matrix/vector (N×N or 1×N)
  • scalar (double): Scalar value for diagonal elements (default: 1.0 for standard identity)
  • block_size_hint (hsize_t): Suggested block size for processing
  • compression_level (int): Compression level (0-9, default: 6)
  • threads (Rcpp::Nullable< int >): Number of threads to use (default: auto-detect)
  • output_type (std::string): Output format: “matrix” for N×N identity matrix, “vector” for 1×N identity vector (default: “matrix”)

Creates an identity matrix multiplied by a scalar value. More efficient than general diagonal matrix for identity cases. Supports both full matrix and vector output formats.


5.1.4 setBlockSize()

void BigDataStatMeth::hdf5DiagonalMatrix::setBlockSize(hsize_t new_block_size)

Set block size for processing.

Parameters:

  • new_block_size (hsize_t): New block size to use

new_block_sizeNew block size to use


5.1.5 getBlockSize()

hsize_t BigDataStatMeth::hdf5DiagonalMatrix::getBlockSize() const

Get current block size.

Returns: Current block size

Current block size


6 Private Implementation

Note

Internal implementation details for advanced users and contributors.

6.1 Methods

6.1.1 writeDiagonal()

void BigDataStatMeth::hdf5DiagonalMatrix::writeDiagonal(hsize_t size, double scalar, const std::vector< double > &diagonal_vector)

Write diagonal elements directly using HDF5 element selection.

Parameters:

  • size (hsize_t): Size of the square matrix
  • scalar (double): Scalar multiplier for diagonal elements
  • diagonal_vector (const std::vector< double > &): Vector of diagonal values

Uses HDF5’s H5Sselect_elements to write all diagonal elements in a single operation. This is ~500x faster than block-based approaches for new datasets as it avoids unnecessary read-modify-write cycles.


6.1.2 writeVectorDiagonal()

void BigDataStatMeth::hdf5DiagonalMatrix::writeVectorDiagonal(hsize_t size, double scalar, const std::vector< double > &diagonal_vector)

Write diagonal values directly as vector dataset.

Parameters:

  • size (hsize_t): Number of diagonal elements to write
  • scalar (double): Scalar multiplier applied to each diagonal element
  • diagonal_vector (const std::vector< double > &): Vector containing base diagonal values

Writes diagonal values to a 1×N vector dataset using optimized direct write. This function bypasses matrix processing entirely and writes diagonal values directly to vector format, providing maximum efficiency for diagonal-only operations.


6.2 Attributes

6.2.1 block_size

Type: hsize_t

Add diagonal elements from two matrices or vectors.


7 Usage Example

#include "hdf5DiagonalMatrix.hpp"

// Example usage
hdf5DiagonalMatrix obj;
// Your code here