From e8f62e83751756879ebadf73cd6aa016e3f5e1b6 Mon Sep 17 00:00:00 2001 From: MatveevDaniil Date: Sun, 28 Jan 2024 17:20:50 -0800 Subject: [PATCH] FIX: converting sparse matrix to a dense vector leads to memory errors for large sparse matrices and slow down program. While converting dense matrix to a sparse matrix have at worst the same time as previous method, works faster sparse matrices and doesn't lead to memory issues. --- R/argchecks_mid.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/argchecks_mid.R b/R/argchecks_mid.R index d096136..e25b725 100644 --- a/R/argchecks_mid.R +++ b/R/argchecks_mid.R @@ -227,7 +227,7 @@ (is.matrix(x) || inherits(x, "sparseMatrix")) && isTRUE(dim(x)[[1]] == dim(x)[[2]]) && Matrix::isSymmetric(x, check.attributes = FALSE) && - all(unique(as.vector(x)) %in% c(0, 1)) + all(Matrix::Matrix(x, sparse = TRUE)@x %in% c(0, 1)) } .MUST.isAdjacencyMatrix <- function(x, name = NULL) { if (is.null(name)) { name <- deparse(substitute(x)) }