Skip to content

Commit 3c913eb

Browse files
committed
Bug fix for sparse matrix
1 parent f27a211 commit 3c913eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

R/mat_util.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#' stoch.W <- normalize.stochastic(W)
3636
normalize.stochastic <- function(obj, ...) {
3737
is_matrix <- FALSE
38+
is_sparse <- FALSE
3839
if (test_numeric(obj, lower = 0, finite = TRUE, any.missing = FALSE,
3940
all.missing = FALSE, null.ok = FALSE) &&
4041
test_atomic_vector(obj)) {
@@ -43,7 +44,7 @@ normalize.stochastic <- function(obj, ...) {
4344
}
4445
} else if (is.dgCMatrix(obj)) {
4546
assert_dgCMatrix(obj)
46-
is_matrix <- TRUE
47+
is_matrix <- is_sparse <- TRUE
4748
} else {
4849
assert(
4950
check_matrix(obj, mode = "numeric", any.missing = FALSE,
@@ -54,7 +55,7 @@ normalize.stochastic <- function(obj, ...) {
5455
is_matrix <- TRUE
5556
}
5657
if (is_matrix) {
57-
sums <- colSums3(obj, !is_matrix)
58+
sums <- colSums3(obj, is_sparse)
5859
if (!all(.equals.double(sums, 1, .001))) {
5960
message("normalizing column vectors!")
6061
empt_col_val <- 1.0 / ncol(obj)
@@ -157,7 +158,7 @@ colSums3 <- function(mat, is.sparse = NULL) {
157158
if (is.sparse) {
158159
sums <- sparseMatrixStats::colSums2(mat)
159160
} else {
160-
sums <- colSums2(mat)
161+
sums <- matrixStats::colSums2(mat)
161162
}
162163
return(sums)
163164
}

0 commit comments

Comments
 (0)