Convert sparse matrix into dense matrix

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

sparse_matrix <- simulate_sparse_matrix(
  2000,
  2000,
  density = 0.01
)

system.time(as.matrix(sparse_matrix))
#>    user  system elapsed 
#>   0.002   0.004   0.006 
system.time(as_matrix(sparse_matrix))
#>    user  system elapsed 
#>   0.001   0.004   0.005 
system.time(as_matrix(sparse_matrix, parallel = TRUE))
#>    user  system elapsed 
#>   0.001   0.004   0.004 

identical(
  as.matrix(sparse_matrix),
  as_matrix(sparse_matrix)
)
#> [1] TRUE

identical(
  as.matrix(sparse_matrix),
  as_matrix(sparse_matrix, parallel = TRUE)
)
#> [1] TRUE

identical(
  sparse_matrix,
  as_matrix(as.matrix(sparse_matrix), sparse = TRUE)
)
#> [1] TRUE

if (FALSE) { # \dontrun{
network_table_0 <- inferCSN(example_matrix)

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

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

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