R Under development (unstable) (2026-01-25 r89330 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # Tests for sparse SVD/PCA > require("irlba") Loading required package: irlba Loading required package: Matrix > loc <- "" > > test <- function() + { + on.exit(message("Error occured in: ", loc)) + loc <<- "sparse SVD" + set.seed(1) + x <- matrix(rnorm(100), 10) + s <- ssvd(x, 1, n=5) + stopifnot(isTRUE(all.equal(sqrt(drop(crossprod(x %*% s$v - s$u %*% s$d))), 0))) + + loc <<- "sparse PCA" + set.seed(1) + x <- matrix(rnorm(100), 10) + s <- ssvd(x, 1, n=5, center=TRUE) + stopifnot(isTRUE(all.equal(sqrt(drop(crossprod(scale(x, center=TRUE, scale=FALSE) %*% s$v - s$u %*% s$d))), 0))) + + loc <<- "sparse PCA + scale" + set.seed(1) + x <- matrix(rnorm(100), 10) + s <- ssvd(x, 1, n=5, center=TRUE, scale.=TRUE) + isTRUE(all.equal(sqrt(drop(crossprod(scale(x, center=TRUE, scale=TRUE) %*% s$v - s$u %*% s$d))), 0)) + + loc <<- "sparse scaled" + set.seed(1) + x <- matrix(rnorm(100), 10) + s <- ssvd(x, 1, n=5, center=FALSE, scale.=TRUE) + isTRUE(all.equal(sqrt(drop(crossprod(scale(x, center=FALSE, scale=TRUE) %*% s$v - s$u %*% s$d))), 0)) + + on.exit() + } > test() > > proc.time() user system elapsed 1.35 0.18 1.51