H5SpMat: Argument list object for using a sparse matrix stored in HDF5...

View source: R/utils.R

H5SpMatR Documentation

Argument list object for using a sparse matrix stored in HDF5 file

Description

For running inmf, onlineINMF or uinmf with sparse matrix stored in HDF5 file, users will need to construct an argument list for the filename of the HDF5 file as well as the paths in the file storing the arrays that construct the CSC (compressed sparse column) matrix. H5SpMat is provided as an instructed constructor. Meanwhile, since the INMF functions require that all datasets should be of the same type, as.H5SpMat is provided for writing in-memory data into a new HDF5 file on disk and returning the constructed argument list.

Usage

H5SpMat(filename, valuePath, rowindPath, colptrPath, nrow, ncol)

as.H5SpMat(x, filename, dataPath, overwrite = FALSE)

## S3 method for class 'matrix'
as.H5SpMat(x, filename, dataPath = "", overwrite = FALSE)

## S3 method for class 'dgCMatrix'
as.H5SpMat(x, filename, dataPath = "", overwrite = FALSE)

## Default S3 method:
as.H5SpMat(x, filename, dataPath = "", overwrite = FALSE, ...)

Arguments

filename

Filename of the HDF5 file

valuePath

Path in the HDF5 file that points to a 1D array storing the non-zero values of the sparse matrix. Default "data" when using as.H5SpMat.

rowindPath

Path in the HDF5 file that points to a 1D integer array storing the row indices of non-zero values in each column of the sparse matrix. Default "indices" when using as.H5SpMat.

colptrPath

Path in the HDF5 file that points to a 1D integer array storing the number of non-zero values in each column of the sparse matrix. Default "indptr" when using as.H5SpMat.

nrow, ncol

Integer, the true dimensionality of the sparse matrix.

x

For as.H5SpMat, matrix of either dense or sparse type to be written; for print, a H5SpMat argument list object.

dataPath

For as.H5SpMat methods, the H5Group name for the sparse matrix. Default "".

overwrite

Logical, whether to overwrite the file if already exists at the given path. Default FALSE.

...

not used

Value

H5SpMat object, indeed a list object.

Examples

if (require("withr")) {
  H5SpMatEx <- function() {
    withr::local_dir(withr::local_tempdir())
    h <- H5SpMat(system.file("extdata/ctrl_sparse.h5", package = "RcppPlanc"),
                 "data", "indices", "indptr", 173, 300)
    dim(h)

    library(Matrix)
    ctrl.dense <- as.matrix(ctrl.sparse)
    h1 <- as.H5SpMat(ctrl.sparse, "ctrl_from_sparse_to_sparse.h5", "matrix")
    h1
    h2 <- as.H5SpMat(ctrl.dense, "ctrl_from_dense_to_sparse.h5", "matrix")
    h2
  }
  H5SpMatEx()
}

RcppPlanc documentation built on April 15, 2025, 1:11 a.m.