Skip to content

Commit 55dae1a

Browse files
committed
Re-export RSpectra::svds
1 parent 91e6db3 commit 55dae1a

6 files changed

Lines changed: 101 additions & 73 deletions

File tree

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: sparseLRMatrix
22
Title: Represent and Use Sparse + Low Rank Matrices
3-
Version: 0.0.0.9000
3+
Version: 0.0.0.9001
44
Authors@R:
55
person(given = "Alex",
66
family = "Hayes",
@@ -21,5 +21,7 @@ Encoding: UTF-8
2121
LazyData: true
2222
Roxygen: list(markdown = TRUE)
2323
RoxygenNote: 7.1.1.9000
24-
URL: https://github.com/RoheLab/sparseLRMatrix
24+
URL: https://rohelab.github.io/sparseLRMatrix, https://github.com/RoheLab/sparseLRMatrix
2525
BugReports: https://github.com/RoheLab/sparseLRMatrix/issues
26+
Suggests:
27+
covr

NAMESPACE

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Generated by roxygen2: do not edit by hand
2-
3-
S3method(svds,sparseLRMatrix)
4-
export(sparseLRMatrix)
5-
import(Matrix)
6-
importFrom(RSpectra,svds)
1+
# Generated by roxygen2: do not edit by hand
2+
3+
S3method(svds,sparseLRMatrix)
4+
export(sparseLRMatrix)
5+
export(svds)
6+
import(Matrix)
7+
importFrom(RSpectra,svds)

R/object.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ setValidity("sparseLRMatrix", function(object) {
4848
return("Number of columns in @sparse must equal number of rows in @V.")
4949
}
5050

51+
if (ncol(object@U) != ncol(object@V)) {
52+
return("Number of columns in @U and @V must match.")
53+
}
54+
5155
TRUE
5256
})
5357

@@ -63,6 +67,9 @@ Atx <- function(x, A) {
6367
drop(out)
6468
}
6569

70+
#' @export
71+
RSpectra::svds
72+
6673
#' Truncated singular value decomposition of a matrix
6774
#'
6875
#' A thin wrapper around [RSpectra::svds()], please see more detailed

README.Rmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ knitr::opts_chunk$set(
1717

1818
<!-- badges: start -->
1919
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
20+
[![Codecov test coverage](https://codecov.io/gh/RoheLab/sparseLRMatrix/branch/master/graph/badge.svg)](https://codecov.io/gh/RoheLab/sparseLRMatrix?branch=master)
21+
[![R-CMD-check](https://github.com/RoheLab/sparseLRMatrix/workflows/R-CMD-check/badge.svg)](https://github.com/RoheLab/sparseLRMatrix/actions)
2022
<!-- badges: end -->
2123

2224
`sparseLRMatrix` provides a single matrix S4 class called `sparseLRMatrix` which represents matrices that can be expressed as the sum of sparse matrix and a low rank matrix. We also provide an efficient SVD method for these matrices by wrapping the `RSpectra` SVD implementation.

README.md

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
2-
<!-- README.md is generated from README.Rmd. Please edit that file -->
3-
4-
# sparseLRMatrix
5-
6-
<!-- badges: start -->
7-
8-
[![Lifecycle:
9-
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
10-
<!-- badges: end -->
11-
12-
`sparseLRMatrix` provides a single matrix S4 class called
13-
`sparseLRMatrix` which represents matrices that can be expressed as the
14-
sum of sparse matrix and a low rank matrix. We also provide an efficient
15-
SVD method for these matrices by wrapping the `RSpectra` SVD
16-
implementation.
17-
18-
Eventually, we will fully subclass `Matrix::Matrix` objects, but the
19-
current implementation is extremely minimal.
20-
21-
## Installation
22-
23-
You can install the released version of sparseLRMatrix from
24-
[CRAN](https://CRAN.R-project.org) with:
25-
26-
``` r
27-
# install.packages("remotes")
28-
remotes::install_github("RoheLab/sparseLRMatrix")
29-
```
30-
31-
## Usage
32-
33-
``` r
34-
library(sparseLRMatrix)
35-
#> Loading required package: Matrix
36-
library(RSpectra)
37-
38-
set.seed(528491)
39-
40-
n <- 50
41-
m <- 40
42-
k <- 3
43-
44-
A <- rsparsematrix(n, m, 0.1)
45-
46-
U <- Matrix(rnorm(n * k), nrow = n, ncol = k)
47-
V <- Matrix(rnorm(m * k), nrow = m, ncol = k)
48-
49-
# construct the matrix, which represents A + U %*% t(V)
50-
X <- sparseLRMatrix(sparse = A, U = U, V = V)
51-
52-
s <- svds(X, 5) # efficient
53-
```
54-
55-
And a quick sanity check
56-
57-
``` r
58-
Y <- A + tcrossprod(U, V)
59-
s2 <- svds(Y, 5) # inefficient, but same calculation
60-
61-
# singular values match up, you can check for yourself
62-
# that the singular vectors do as well!
63-
all.equal(s$d, s2$d)
64-
#> [1] TRUE
65-
```
1+
2+
<!-- README.md is generated from README.Rmd. Please edit that file -->
3+
4+
# sparseLRMatrix
5+
6+
<!-- badges: start -->
7+
8+
[![Lifecycle:
9+
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
10+
<!-- badges: end -->
11+
12+
`sparseLRMatrix` provides a single matrix S4 class called
13+
`sparseLRMatrix` which represents matrices that can be expressed as the
14+
sum of sparse matrix and a low rank matrix. We also provide an efficient
15+
SVD method for these matrices by wrapping the `RSpectra` SVD
16+
implementation.
17+
18+
Eventually, we will fully subclass `Matrix::Matrix` objects, but the
19+
current implementation is extremely minimal.
20+
21+
## Installation
22+
23+
You can install the released version of sparseLRMatrix from
24+
[CRAN](https://CRAN.R-project.org) with:
25+
26+
``` r
27+
# install.packages("remotes")
28+
remotes::install_github("RoheLab/sparseLRMatrix")
29+
```
30+
31+
## Usage
32+
33+
``` r
34+
library(sparseLRMatrix)
35+
#> Loading required package: Matrix
36+
library(RSpectra)
37+
38+
set.seed(528491)
39+
40+
n <- 50
41+
m <- 40
42+
k <- 3
43+
44+
A <- rsparsematrix(n, m, 0.1)
45+
46+
U <- Matrix(rnorm(n * k), nrow = n, ncol = k)
47+
V <- Matrix(rnorm(m * k), nrow = m, ncol = k)
48+
49+
# construct the matrix, which represents A + U %*% t(V)
50+
X <- sparseLRMatrix(sparse = A, U = U, V = V)
51+
52+
s <- svds(X, 5) # efficient
53+
```
54+
55+
And a quick sanity check
56+
57+
``` r
58+
Y <- A + tcrossprod(U, V)
59+
s2 <- svds(Y, 5) # inefficient, but same calculation
60+
61+
# singular values match up, you can check for yourself
62+
# that the singular vectors do as well!
63+
all.equal(s$d, s2$d)
64+
#> [1] TRUE
65+
```

man/reexports.Rd

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)