From de2d7dd4001513a0248452d104999cb6de7abaa1 Mon Sep 17 00:00:00 2001 From: Peter Carbonetto Date: Wed, 24 Aug 2022 11:27:18 -0500 Subject: [PATCH] Replaced dgCMatrix with CsparseMatrix in tests. --- DESCRIPTION | 2 +- R/fit_poisson_nmf.R | 2 +- tests/testthat/test_de_analysis.R | 6 +++--- tests/testthat/test_fit_multinom_model.R | 2 +- tests/testthat/test_fit_poisson_nmf.R | 6 +++--- tests/testthat/test_likelihood.R | 10 +++++----- tests/testthat/test_poisson2multinom.R | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d6dd08a5..09039406 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Type: Package Package: fastTopics -Version: 0.6-138 +Version: 0.6-139 Date: 2022-08-24 Title: Fast Algorithms for Fitting Topic Models and Non-Negative Matrix Factorizations to Count Data diff --git a/R/fit_poisson_nmf.R b/R/fit_poisson_nmf.R index 120fc71e..e81daaf6 100644 --- a/R/fit_poisson_nmf.R +++ b/R/fit_poisson_nmf.R @@ -428,7 +428,7 @@ fit_poisson_nmf <- function (X, k, fit0, numiter = 100, method.text <- "CCD" cat(sprintf("Running %d %s updates, %s extrapolation ",numiter, method.text,ifelse(control$extrapolate,"with","without"))) - cat("(fastTopics 0.6-138).\n") + cat("(fastTopics 0.6-139).\n") } # INITIALIZE ESTIMATES diff --git a/tests/testthat/test_de_analysis.R b/tests/testthat/test_de_analysis.R index c18f5026..6e9187f7 100644 --- a/tests/testthat/test_de_analysis.R +++ b/tests/testthat/test_de_analysis.R @@ -86,7 +86,7 @@ test_that(paste("All variants of fit_poisson_models should produce the", out <- add_pseudocounts(X,s*L,0.1) X <- out$X L <- out$L - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") # Fit the univariate Poisson models using glm and scd. F1 <- fit_poisson_models(X,L,method = "glm") @@ -115,7 +115,7 @@ test_that(paste("de_analysis with and without multithreading, using a", k <- 4 dat <- simulate_multinom_gene_data(n,m,k,sparse = FALSE) X <- dat$X - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") L <- dat$L # Run de_analysis twice, using the single-threaded computations (nc @@ -161,7 +161,7 @@ test_that(paste("de_analysis with and without multithreading, using a", k <- 4 dat <- simulate_multinom_gene_data(n,m,k,sparse = FALSE) X <- dat$X - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") L <- dat$L # Run de_analysis twice, using the single-threaded computations (nc diff --git a/tests/testthat/test_fit_multinom_model.R b/tests/testthat/test_fit_multinom_model.R index efaaf4b1..684cab45 100644 --- a/tests/testthat/test_fit_multinom_model.R +++ b/tests/testthat/test_fit_multinom_model.R @@ -9,7 +9,7 @@ test_that("fit_multinom_model gives correct factor estimates",{ k <- 3 out <- simulate_toy_gene_data(n,m,k,s = 1000) X <- out$X - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") # Force "hard" topic assignments. cluster <- factor(apply(force_hard_topic_assignments(out$L),1,which.max)) diff --git a/tests/testthat/test_fit_poisson_nmf.R b/tests/testthat/test_fit_poisson_nmf.R index 9b655c55..20d69247 100644 --- a/tests/testthat/test_fit_poisson_nmf.R +++ b/tests/testthat/test_fit_poisson_nmf.R @@ -87,7 +87,7 @@ test_that(paste("multiplicative and EM updates produce same result, and", control = list(numiter = 1,nc = nc))) # Store the counts as a sparse matrix. - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") # Run 20 EM updates a third time, this time using the sparse counts # matrix. @@ -165,7 +165,7 @@ test_that(paste("ccd and scd updates produce the same result, and", control = list(numiter = 1,nc = 1))) # Redo the SCD updates with a sparse matrix. - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") capture.output( fit3 <- fit_poisson_nmf(Y,fit0 = fit0,numiter = numiter,method = "scd", control = list(numiter = 1,nc = 1))) @@ -492,7 +492,7 @@ test_that("Fixed factors and loadings to not change (aside from rescaling)",{ k <- 3 out <- generate_test_data(n,m,k) X <- out$X - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") # Check that the factors remain the same (up to a rescaling) when # update.factors is NULL. diff --git a/tests/testthat/test_likelihood.R b/tests/testthat/test_likelihood.R index 9d105e5e..3f244887 100644 --- a/tests/testthat/test_likelihood.R +++ b/tests/testthat/test_likelihood.R @@ -12,7 +12,7 @@ test_that(paste("R and Rcpp versions of cost function return same result", X <- out$X F <- out$F L <- out$L - Y <- as(X,"dgCMatrix") + Y <- as(X,"CsparseMatrix") # Compute the loss function. f1 <- cost(X,L,t(F),version = "R") @@ -43,7 +43,7 @@ test_that(paste("loglik_poisson_nmf gives correct result for sparse and", # Compute the log-likelikhood. f1 <- loglik_poisson_nmf_with_dpois(X,fit) f2 <- loglik_poisson_nmf(X,fit,e = 0) - f3 <- loglik_poisson_nmf(as(X,"dgCMatrix"),fit,e = 0) + f3 <- loglik_poisson_nmf(as(X,"CsparseMatrix"),fit,e = 0) names(f1) <- rownames(X) # The likelihood calculations should all be the same. @@ -68,7 +68,7 @@ test_that(paste("loglik_multinom_topic_model gives correct result for", # Compute the log-likelikhood. f1 <- loglik_multinom_topic_model_with_dmultinom(X,poisson2multinom(fit)) f2 <- loglik_multinom_topic_model(X,fit,e = 0) - f3 <- loglik_multinom_topic_model(as(X,"dgCMatrix"),fit,e = 0) + f3 <- loglik_multinom_topic_model(as(X,"CsparseMatrix"),fit,e = 0) # Compute the multinomial log-likelihood a different way: first # compute the Poisson log-likelihood, then subtract out the @@ -98,7 +98,7 @@ test_that(paste("deviance_poisson_topic_nmf gives correct result for sparse", # Compute the deviances. d1 <- deviance_poisson_nmf_with_poisson(X,fit) d2 <- deviance_poisson_nmf(X,fit,e = 0) - d3 <- deviance_poisson_nmf(as(X,"dgCMatrix"),fit,e = 0) + d3 <- deviance_poisson_nmf(as(X,"CsparseMatrix"),fit,e = 0) # The deviance calculations should all be the same. expect_equal(d1,d2) @@ -117,7 +117,7 @@ test_that("poisson_nmf_kkt gives same result for sparse and dense matrices",{ # Compute the KKT residuals, and check that they are the same. out1 <- poisson_nmf_kkt(X,F,L) - out2 <- poisson_nmf_kkt(as(X,"dgCMatrix"),F,L) + out2 <- poisson_nmf_kkt(as(X,"CsparseMatrix"),F,L) expect_equal(out1,out2,tolerance = 1e-15,scale = 1) }) diff --git a/tests/testthat/test_poisson2multinom.R b/tests/testthat/test_poisson2multinom.R index abfcb412..5ecc0b0f 100644 --- a/tests/testthat/test_poisson2multinom.R +++ b/tests/testthat/test_poisson2multinom.R @@ -34,7 +34,7 @@ test_that("multinom2poisson recovers original Poisson NMF model fit",{ fit2a$s <- NULL fit3 <- multinom2poisson(fit2) fit4 <- multinom2poisson(fit2a,X) - fit5 <- multinom2poisson(fit2a,as(X,"dgCMatrix")) + fit5 <- multinom2poisson(fit2a,as(X,"CsparseMatrix")) Y1 <- with(fit1,tcrossprod(L,F)) Y3 <- with(fit3,tcrossprod(L,F)) Y4 <- with(fit4,tcrossprod(L,F))