diff --git a/DESCRIPTION b/DESCRIPTION index 451543d..55019bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Encoding: UTF-8 Type: Package Package: fastglmpca -Version: 0.1-104 +Version: 0.1-105 Date: 2024-01-30 Title: Fast Algorithms for Generalized Principal Component Analysis Authors@R: c(person("Eric","Weine",role=c("aut","cre"), @@ -44,4 +44,4 @@ LazyData: true LazyDataCompression: xz NeedsCompilation: yes VignetteBuilder: knitr -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 diff --git a/R/argument_checking.R b/R/argument_checking.R index c0c3642..551d346 100644 --- a/R/argument_checking.R +++ b/R/argument_checking.R @@ -1,7 +1,7 @@ # Return true if x is a compressed, sparse, column-oriented numeric # matrix. is.sparse.matrix <- function (x) - inherits(x,"dgCMatrix") && is.numeric(x@x) + inherits(x,"dsparseMatrix") && is.numeric(x@x) # Verify that x is matrix with finite, numeric entries. verify.matrix <- function (x, arg.name = deparse(substitute(x))) { diff --git a/R/fit.R b/R/fit.R index ed9a55b..5747945 100644 --- a/R/fit.R +++ b/R/fit.R @@ -108,7 +108,7 @@ #' #' @param Y The n x m matrix of counts; all entries of \code{Y} should #' be non-negative. It can be a sparse matrix (class -#' \code{"dgCMatrix"}) or dense matrix (class \code{"matrix"}). +#' \code{"dsparseMatrix"}) or dense matrix (class \code{"matrix"}). #' #' @param K Integer 1 or greater specifying the rank of the matrix #' factorization. This should only be provided if the initial fit diff --git a/man/fit_glmpca_pois.Rd b/man/fit_glmpca_pois.Rd index ba8b756..12a512f 100644 --- a/man/fit_glmpca_pois.Rd +++ b/man/fit_glmpca_pois.Rd @@ -34,7 +34,7 @@ init_glmpca_pois( \arguments{ \item{Y}{The n x m matrix of counts; all entries of \code{Y} should be non-negative. It can be a sparse matrix (class -\code{"dgCMatrix"}) or dense matrix (class \code{"matrix"}).} +\code{"dsparseMatrix"}) or dense matrix (class \code{"matrix"}).} \item{K}{Integer 1 or greater specifying the rank of the matrix factorization. This should only be provided if the initial fit diff --git a/tests/testthat/test_fit_glmpca_pois.R b/tests/testthat/test_fit_glmpca_pois.R index 5d4adf9..50c12fb 100644 --- a/tests/testthat/test_fit_glmpca_pois.R +++ b/tests/testthat/test_fit_glmpca_pois.R @@ -282,3 +282,44 @@ test_that("Test fit works with input covariates",{ expect_equivalent(crossprod(fit_quick$U),diag(3),scale = 1,tolerance = 1e-8) expect_equivalent(crossprod(fit_quick$V),diag(3),scale = 1,tolerance = 1e-8) }) + +test_that("Results are the same with different classes of sparse matrices",{ + + # Simulate a 100 x 200 data set to factorize. + set.seed(1) + n <- 100 + m <- 200 + Y <- generate_glmpca_data_pois(n,m,K = 3)$Y + + Y_dgC <- as(Y, "CsparseMatrix") + Y_dgT <- as(Y, "dgTMatrix") + Y_dgR <- as(Y, "dgRMatrix") + + set.seed(1) + fit0_dgC <- init_glmpca_pois(Y_dgC,K = 3) + set.seed(1) + fit0_dgT <- init_glmpca_pois(Y_dgT,K = 3) + set.seed(1) + fit0_dgR <- init_glmpca_pois(Y_dgR,K = 3) + + suppressWarnings(capture.output( + fit_quick_dgC <- fit_glmpca_pois(Y_dgC,fit0 = fit0_dgC, + control = list(maxiter = 20)))) + + suppressWarnings(capture.output( + fit_quick_dgT <- fit_glmpca_pois(Y_dgT,fit0 = fit0_dgT, + control = list(maxiter = 20)))) + + suppressWarnings(capture.output( + fit_quick_dgR <- fit_glmpca_pois(Y_dgR,fit0 = fit0_dgR, + control = list(maxiter = 20)))) + + expect_equal(fit_quick_dgC$progress$loglik, fit_quick_dgR$progress$loglik) + expect_equal(fit_quick_dgC$progress$loglik, fit_quick_dgT$progress$loglik) + expect_equal(fit_quick_dgC$U, fit_quick_dgR$U) + expect_equal(fit_quick_dgC$d, fit_quick_dgR$d) + expect_equal(fit_quick_dgC$V, fit_quick_dgR$V) + expect_equal(fit_quick_dgC$U, fit_quick_dgT$U) + expect_equal(fit_quick_dgC$d, fit_quick_dgT$d) + expect_equal(fit_quick_dgC$V, fit_quick_dgT$V) +})