35
35
# ' stoch.W <- normalize.stochastic(W)
36
36
normalize.stochastic <- function (obj , ... ) {
37
37
is_matrix <- FALSE
38
+ is_sparse <- FALSE
38
39
if (test_numeric(obj , lower = 0 , finite = TRUE , any.missing = FALSE ,
39
40
all.missing = FALSE , null.ok = FALSE ) &&
40
41
test_atomic_vector(obj )) {
@@ -43,7 +44,7 @@ normalize.stochastic <- function(obj, ...) {
43
44
}
44
45
} else if (is.dgCMatrix(obj )) {
45
46
assert_dgCMatrix(obj )
46
- is_matrix <- TRUE
47
+ is_matrix <- is_sparse <- TRUE
47
48
} else {
48
49
assert(
49
50
check_matrix(obj , mode = " numeric" , any.missing = FALSE ,
@@ -54,7 +55,7 @@ normalize.stochastic <- function(obj, ...) {
54
55
is_matrix <- TRUE
55
56
}
56
57
if (is_matrix ) {
57
- sums <- colSums3(obj , ! is_matrix )
58
+ sums <- colSums3(obj , is_sparse )
58
59
if (! all(.equals.double(sums , 1 , .001 ))) {
59
60
message(" normalizing column vectors!" )
60
61
empt_col_val <- 1.0 / ncol(obj )
@@ -157,7 +158,7 @@ colSums3 <- function(mat, is.sparse = NULL) {
157
158
if (is.sparse ) {
158
159
sums <- sparseMatrixStats :: colSums2(mat )
159
160
} else {
160
- sums <- colSums2(mat )
161
+ sums <- matrixStats :: colSums2(mat )
161
162
}
162
163
return (sums )
163
164
}
0 commit comments