Skip to content

Commit e108962

Browse files
committed
Add basic SVD equivalence test
1 parent 55dae1a commit e108962

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Package: sparseLRMatrix
22
Title: Represent and Use Sparse + Low Rank Matrices
3-
Version: 0.0.0.9001
3+
Version: 0.0.0.9002
44
Authors@R:
55
person(given = "Alex",
66
family = "Hayes",
7-
role = c("aut", "cre"),
7+
role = c("aut", "cre", "cph"),
88
email = "alexpghayes@gmail.com",
99
comment = c(ORCID = "0000-0002-4985-5160"))
1010
Description: Provides an S4 class for representing and
@@ -24,4 +24,6 @@ RoxygenNote: 7.1.1.9000
2424
URL: https://rohelab.github.io/sparseLRMatrix, https://github.com/RoheLab/sparseLRMatrix
2525
BugReports: https://github.com/RoheLab/sparseLRMatrix/issues
2626
Suggests:
27-
covr
27+
covr,
28+
testthat (>= 3.0.0)
29+
Config/testthat/edition: 3

tests/testthat.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library(testthat)
2+
library(sparseLRMatrix)
3+
4+
test_check("sparseLRMatrix")

tests/testthat/test-svds-matches.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
test_that("singular values match", {
2+
3+
set.seed(528491)
4+
5+
n <- 50
6+
m <- 40
7+
k <- 3
8+
9+
A <- rsparsematrix(n, m, 0.1)
10+
11+
U <- Matrix(rnorm(n * k), nrow = n, ncol = k)
12+
V <- Matrix(rnorm(m * k), nrow = m, ncol = k)
13+
14+
# construct the matrix, which represents A + U %*% t(V)
15+
X <- sparseLRMatrix(sparse = A, U = U, V = V)
16+
17+
s <- svds(X, 5) # efficient
18+
19+
Y <- A + tcrossprod(U, V)
20+
s2 <- svds(Y, 5) # inefficient, but same calculation
21+
22+
expect_equal(s, s2)
23+
})

0 commit comments

Comments
 (0)