# Low rank SVD

**URL:** <https://discourse.julialang.org/t/low-rank-svd/53529>\
**Category:** Performance\
**Tags:** question, linearalgebra\
**Created:** [January 18, 2021, 10:05am UTC](https://discourse.julialang.org/t/low-rank-svd/53529 "2021-01-18T10:05:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [January 18, 2021, 10:05am UTC](https://discourse.julialang.org/t/low-rank-svd/53529/1 "2021-01-18T10:05:03Z")

</div>

I need to calculate a low rank SVD of a large matrix for a pseudoinverse, but I also need the individual matrices. I currently do I like this:

```julia
X_svd = svd(X)

r = 20
U = X_svd.U[:, 1:r]
Σ = Diagonal(X_svd.S[1:r])
Vt = X_svd.Vt[1:r, :]

```

`svd` does not have a parameter to produce the low rank approximations, interestingly `pinv` has an option for that (`atol` and `rtol`).

Am I right that this is a limitation of LAPACK and not julia calling it? I don’t know much about the algorithmic side of this, how large are the potential gains (computation and memory) when only calculating a lower rank?

I found [LowRankApprox.jl](https://github.com/JuliaMatrices/LowRankApprox.jl/) but I have yet to try it.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [January 18, 2021, 10:07am UTC](https://discourse.julialang.org/t/low-rank-svd/53529/2 "2021-01-18T10:07:11Z")

</div>

You may find algorithms in  
[https://github.com/haampie/RandomizedLinAlg.jl](https://github.com/haampie/RandomizedLinAlg.jl)  
and  
[https://github.com/JuliaLinearAlgebra/TSVD.jl](https://github.com/JuliaLinearAlgebra/TSVD.jl)  
helpful. They allow you to compute a rank-r approximation to the SVD without having to compute the entire factorization.

---

<div class="post-metadata">

**Author:** ![moeddel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moeddel/32/18641_2.png) [@moeddel](https://discourse.julialang.org/u/moeddel)\
**Post date:** [January 18, 2021, 10:52am UTC](https://discourse.julialang.org/t/low-rank-svd/53529/3 "2021-01-18T10:52:25Z")

</div>

What dimensions does `X` has?

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [January 18, 2021, 8:53pm UTC](https://discourse.julialang.org/t/low-rank-svd/53529/4 "2021-01-18T20:53:18Z")

</div>

Thanks, I will try out the different packages and see if there is a performance difference!
