# Choosing algorithm for SVD

**URL:** <https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249>\
**Category:** General Usage\
**Tags:** cuda, linearalgebra\
**Created:** [March 1, 2021, 1:00pm UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249 "2021-03-01T13:00:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Post date:** [March 1, 2021, 1:00pm UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/1 "2021-03-01T13:00:59Z")

</div>

The svd function in LinearAlgebra package has an option to select the algorithm for factorization method. But could not find proper way to use it.

```julia
using LinearAlgebra
A= rand(Float32, 10, 20);
F = svd(A, full=true) # works fine 
F2 = svd(A, full=true, alg=QRIteration()) # does not work

```

Asks me to use LinearAlgebra.Algorithm and when I use it :

```julia
F2 = svd(A, full=true, alg=LinearAlgebra.QRIteration())
#throws and error saying

ERROR: TypeError: in keyword argument alg, expected LinearAlgebra.Algorithm, got Type{LinearAlgebra.QRIteration}

```

What is the proper use of another algorithm for svd ?  
Yet another question is can svd be used with CUDA.jl ?

B.R.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 1, 2021, 1:52pm UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/2 "2021-03-01T13:52:49Z")

</div>

> [@kadir-gunel](#):
>
> `F2 = svd(A, full=true, alg=LinearAlgebra.QRIteration())`

This works for me with Julia 1.5.3. What version of Julia are you using?

---

<div class="post-metadata">

**Author:** ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Post date:** [March 2, 2021, 6:48am UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/3 "2021-03-02T06:48:12Z")

</div>

versioninfo() shows 1.5.2 . Probably, I didn’t write it as a function call QRIteration().

Thaks

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [March 2, 2021, 6:50am UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/4 "2021-03-02T06:50:35Z")

</div>

Is there a reason we have to write the function with `()` at the end? This seems inconsistent with the way other functions are passed as arguments, e.g. `sum(exp, rand(5))`.

---

<div class="post-metadata">

**Author:** ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)\
**Post date:** [March 2, 2021, 7:49am UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/5 "2021-03-02T07:49:59Z")

</div>

> Is there a reason we have to write the function with `()` at the end? This seems inconsistent with the way other functions are passed as arguments, e.g. `sum(exp, rand(5))` .

nice point

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 2, 2021, 11:07am UTC](https://discourse.julialang.org/t/choosing-algorithm-for-svd/56249/6 "2021-03-02T11:07:17Z")

</div>

> [@maxkapur](#):
>
> Is there a reason we have to write the function with `()` at the end?

`LinearAlgebra.QRIteration()` is a call to a constructor (for the [QRIteration](https://github.com/JuliaLang/julia/blob/dc81980e0b9ea4f817fc1a36139867469da0f594/stdlib/LinearAlgebra/src/LinearAlgebra.jl#L165) type), it’s not a function like `exp`.
