sparseToDenseMatrix: Convert a sparse matrix to a dense matrix in a block-wise...

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Convert a sparse matrix to a dense matrix in a block-wise fashion

Usage

1
2
3
4
5
6
7
8
9
sparseToDenseMatrix(
  mat,
  blockwise = TRUE,
  by.row = TRUE,
  by.col = FALSE,
  chunk.size = 100000,
  parallel = FALSE,
  cores = 2
)

Arguments

mat

Input sparse matrix

blockwise

Whether to do the coercion in a block-wise manner

by.row

Whether to chunk in a row-wise fashion

by.col

Whether to chunk in a column-wise fashion

chunk.size

The size of the chunks to use for coercion

parallel

Whether to perform the coercion in parallel

cores

The number of cores to use in the parallel coercion

Value

A dense matrix of the same dimensions as the input

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#make a sparse binary matrix
library(Matrix)
m <- 100
n <- 1000
mat <- round(matrix(runif(m*n), m, n))
mat.sparse <- Matrix(mat, sparse = TRUE)

#coerce back
mat.dense <- sparseToDenseMatrix(mat.sparse, chunk.size = 10)

#make sure they are the same dimensions
dim(mat) == dim(mat.dense)

#make sure they are the same numerically
all(mat == mat.dense)

JordanVeldboom/compartmap documentation built on July 3, 2020, 6:32 p.m.