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

Implement a fast SVD routine #105

Open
romeric opened this issue Jun 8, 2020 · 2 comments
Open

Implement a fast SVD routine #105

romeric opened this issue Jun 8, 2020 · 2 comments

Comments

@romeric
Copy link
Owner

romeric commented Jun 8, 2020

At the moment Fastor provides the fastest LU decomposition, inversion and solve routines for small tensors but lacks a fast SVD routine

@dynamic-queries
Copy link

I am interested in contributing to this issue.
Did you have anything specific in mind?

@romeric
Copy link
Owner Author

romeric commented May 21, 2021

Absolutely, go ahead!
The only requirement we have is that you need to add unittests for it and it has to be sufficiently fast. Look at the signature of lu and qr function for reference here.

A very naive, inefficient and perhaps buggy solution would be (just for your reference)

template<typename T, size_t M, size_t N>
inline void svd(const Tensor<T,M,N> &a, Tensor<T,M,M> &u, Tensor<T,N,M> &s, Tensor<T,N,N> &v, const T tol=1e-10) {

    // reserve space in advance
    size_t maxiter = 100*std::max(M,N);
    size_t counter = 0;
    u.eye2();
    s = transpose(a);
    v.eye2();
    Tensor<T,M,M> q;
    T err = std::numeric_limits<T>::max();
    while (err > tol && counter < maxiter) {
        qr(transpose(s),q,s); u = u % q;
        qr(transpose(s),q,s); v = v % q;
        T F = sum(diag(s));
        if (std::abs(F) < tol) F = 1;
        err = E/F;
        counter++;
    }
    return;
}

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

No branches or pull requests

2 participants