From ce7f42bbb338fcd4093a31932701274572a6406c Mon Sep 17 00:00:00 2001 From: Ted Enamorado Date: Thu, 16 Nov 2023 23:08:06 -0600 Subject: [PATCH] fixing issues with Matrix class --- R/gammaCK2par.R | 8 +++++++- R/gammaCKpar.R | 10 ++++++++-- R/gammaNUMCK2par.R | 8 +++++++- R/gammaNUMCKpar.R | 10 +++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/R/gammaCK2par.R b/R/gammaCK2par.R index 7148bbc..f0a0423 100644 --- a/R/gammaCK2par.R +++ b/R/gammaCK2par.R @@ -126,7 +126,13 @@ gammaCK2par <- function(matAp, matBp, n.cores = NULL, cut.a = 0.92, method = "jw t <- Matrix(t, sparse = T) } - t@x[t@x >= cut] <- 2; gc() + if(is(t, "ddiMatrix")) { + t <- t * 2 + } else { + t@x[t@x >= cut] <- 2 + } + gc() + slice.1 <- m[[2]] slice.2 <- y[[2]] indexes.2 <- which(t == 2, arr.ind = T) diff --git a/R/gammaCKpar.R b/R/gammaCKpar.R index fb01afc..7c380c8 100644 --- a/R/gammaCKpar.R +++ b/R/gammaCKpar.R @@ -128,8 +128,14 @@ gammaCKpar <- function(matAp, matBp, n.cores = NULL, cut.a = 0.92, cut.p = 0.88, t <- Matrix(t, sparse = T) } - t@x[t@x >= cut[1]] <- 2 - t@x[t@x >= cut[2] & t@x < cut[1]] <- 1; gc() + if(is(t, "ddiMatrix")) { + t <- t * 2 + } else { + t@x[t@x >= cut[1]] <- 2 + t@x[t@x >= cut[2] & t@x < cut[1]] <- 1 + } + gc() + slice.1 <- m[[2]] slice.2 <- y[[2]] indexes.2 <- which(t == 2, arr.ind = T) diff --git a/R/gammaNUMCK2par.R b/R/gammaNUMCK2par.R index 4b0a96c..fd1e374 100644 --- a/R/gammaNUMCK2par.R +++ b/R/gammaNUMCK2par.R @@ -89,7 +89,13 @@ gammaNUMCK2par <- function(matAp, matBp, n.cores = NULL, cut.a = 1) { t[ t > cut ] <- 0 t <- Matrix(t, sparse = T) - t@x[t@x <= cut] <- 2; gc() + if(is(t, "ddiMatrix")) { + t <- t * 2 + } else { + t@x[t@x <= cut] <- 2 + } + gc() + slice.1 <- m[[2]] slice.2 <- y[[2]] indexes.2 <- which(t == 2, arr.ind = T) diff --git a/R/gammaNUMCKpar.R b/R/gammaNUMCKpar.R index 51c67e2..d2046fe 100644 --- a/R/gammaNUMCKpar.R +++ b/R/gammaNUMCKpar.R @@ -83,9 +83,13 @@ gammaNUMCKpar <- function(matAp, matBp, n.cores = NULL, cut.a = 1, cut.p = 2) { t[ t > cut[2] ] <- 0 t <- Matrix(t, sparse = T) - t@x[t@x <= cut[1]] <- cut[2] + 1; gc() - t@x[t@x > cut[1] & t@x <= cut[2]] <- 1; gc() - + if(is(t, "ddiMatrix")) { + t <- t * (cut[2] + 1) + } else { + t@x[t@x <= cut[1]] <- cut[2] + 1; gc() + t@x[t@x > cut[1] & t@x <= cut[2]] <- 1; gc() + } + slice.1 <- m[[2]] slice.2 <- y[[2]] indexes.2 <- which(t == cut[2] + 1, arr.ind = T)