Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose C++ multiplication interface #64

Open
alexpghayes opened this issue Mar 4, 2022 · 2 comments
Open

Expose C++ multiplication interface #64

alexpghayes opened this issue Mar 4, 2022 · 2 comments

Comments

@alexpghayes
Copy link

Hey there!

My lab spends a lot of time taking SVDs of, let's say, "nearly nice" matrices. For these matrices, we can often compute t(A) %*% x and A %*% x in a reasonable amount of time if we give A a custom class and then implement the multiplication in C++ via RcppEigen. In our cases, A is often sparse, and this introduces a problem. While we can implement matrix multiplication in C++ and make it fast, using sparse matrices incurs a copying cost. This makes irlba slow for us: either we implement matrix multiplication in R, which is slow in our case, or we do it in C++, and pay many copying costs for each SVD. We have to take the SVD many times since we're doing matrix completion work, and anyway this all adds up.

Ideally, irlba would expose a C++ level interface, so that we could copy A just once for each SVD, or even better, just once for the whole matrix completion algorithm if we implemented it in C++. For example, spectra does this for eigendecompositions, and make custom eigendecompositions very nice via the "custom op" interface at the C++ level. However, it doesn't seem like irlba offers the same functionality, even though it seems like irlba may be more appropriate for SVDs (yixuan/spectra#11).

I know this is a large ask, but would you consider (possibly in the long term) refactoring the C/C++ code to a structure more like spectra so that we can take advantage of irlba's SVD implementation?

@alexpghayes
Copy link
Author

#53 seems related

@LTLA
Copy link
Contributor

LTLA commented Mar 4, 2022

FWIW there is a pure C++ implementation at https://github.com/LTLA/CppIrlba, derived from the code here. I have used it to implement custom multiplications at the C++ level, see e.g. here and here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants