as_matrix: Convert dgCMatrix into a dense matrix

View source: R/utils.R

as_matrixR Documentation

Convert dgCMatrix into a dense matrix

Description

Convert dgCMatrix into a dense matrix

Usage

as_matrix(x, parallel = FALSE, sparse = FALSE)

Arguments

x

A matrix.

parallel

Logical value, default is FALSE. Setting to parallelize the computation with setThreadOptions.

sparse

Logical value, default is FALSE, whether to output a sparse matrix.

Examples

dims_i <- 2000
dims_j <- 2000
sparse_matrix <- Matrix::sparseMatrix(
  i = sample(1:dims_i, 500),
  j = sample(1:dims_j, 500),
  x = rnorm(500),
  dims = c(dims_i, dims_j),
  dimnames = list(
    paste0("a", rep(1:dims_i)),
    paste0("b", rep(1:dims_j))
  )
)

system.time(as.matrix(sparse_matrix))
system.time(as_matrix(sparse_matrix))
system.time(as_matrix(sparse_matrix, parallel = TRUE))

identical(
  as.matrix(sparse_matrix),
  as_matrix(sparse_matrix)
)

identical(
  as.matrix(sparse_matrix),
  as_matrix(sparse_matrix, parallel = TRUE)
)

identical(
  sparse_matrix,
  as_matrix(as.matrix(sparse_matrix), sparse = TRUE)
)

## Not run: 
network_table_1 <- inferCSN(
  as_matrix(example_matrix, sparse = TRUE)
)
network_table_2 <- inferCSN(
  as(example_matrix, "sparseMatrix")
)

plot_scatter(
  data.frame(
    network_table_1$weight,
    network_table_2$weight
  ),
  legend_position = "none"
)

## End(Not run)

inferCSN documentation built on Sept. 11, 2024, 9:32 p.m.