Retrieves the diagonal elements from a matrix stored in an HDF5 file.
2 Usage
bdgetDiagonal_hdf5(filename, group, dataset)
3 Arguments
Parameter
Description
filename
Character string. Path to the HDF5 file.
group
Character string. Path to the group containing the dataset.
dataset
Character string. Name of the dataset.
4 Value
Numeric vector containing diagonal elements.
5 Details
This function provides efficient access to matrix diagonal elements with: - Access features: - Direct diagonal access - Memory-efficient retrieval - Support for large matrices - Implementation features: - Safe HDF5 file operations - Memory-efficient implementation - Comprehensive error handling - Read-only access to files
The function opens the HDF5 file in read-only mode to ensure data safety.
6 Examples
Code
library(BigDataStatMeth)# Create test matrixX <-matrix(rnorm(100), 10, 10)diag(X) <-0.5# Save to HDF5bdCreate_hdf5_matrix("test.hdf5", X, "data", "matrix1",overwriteFile =TRUE)# Get diagonaldiag_elements <-bdgetDiagonal_hdf5("test.hdf5", "data", "matrix1")print(diag_elements)# Cleanupif (file.exists("test.hdf5")) {file.remove("test.hdf5")}
---title: "bdgetDiagonal_hdf5"subtitle: "bdgetDiagonal_hdf5"---<span class="category-badge hdf5_algebra">HDF5_ALGEBRA</span>## DescriptionRetrieves the diagonal elements from a matrix stored in an HDF5 file.## Usage```rbdgetDiagonal_hdf5(filename, group, dataset)```## Arguments::: {.param-table}| Parameter | Description ||-----------|-------------||`filename`| Character string. Path to the HDF5 file. ||`group`| Character string. Path to the group containing the dataset. ||`dataset`| Character string. Name of the dataset. |:::## Value::: {.return-value}Numeric vector containing diagonal elements.:::## DetailsThis function provides efficient access to matrix diagonal elements with:- Access features: - Direct diagonal access - Memory-efficient retrieval - Support for large matrices- Implementation features: - Safe HDF5 file operations - Memory-efficient implementation - Comprehensive error handling - Read-only access to filesThe function opens the HDF5 file in read-only mode to ensure data safety.## Examples```{r}#| eval: false#| code-fold: showlibrary(BigDataStatMeth)# Create test matrixX <-matrix(rnorm(100), 10, 10)diag(X) <-0.5# Save to HDF5bdCreate_hdf5_matrix("test.hdf5", X, "data", "matrix1",overwriteFile =TRUE)# Get diagonaldiag_elements <-bdgetDiagonal_hdf5("test.hdf5", "data", "matrix1")print(diag_elements)# Cleanupif (file.exists("test.hdf5")) {file.remove("test.hdf5")}```## See Also::: {.see-also}- [bdWriteDiagonal_hdf5](bdWriteDiagonal_hdf5.html) for writing diagonal elements- [bdCreate_hdf5_matrix](../hdf5_io_management/bdCreate_hdf5_matrix.html) for creating HDF5 matrices:::