# KrylovKit svdsolve not working

**URL:** <https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993>\
**Category:** New to Julia\
**Created:** [November 23, 2024, 1:35pm UTC](https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993 "2024-11-23T13:35:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EZ\_Money](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ez_money/32/213637_2.png) [@EZ\_Money](https://discourse.julialang.org/u/EZ_Money)\
**Post date:** [November 23, 2024, 1:35pm UTC](https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993/1 "2024-11-23T13:35:23Z")

</div>

Hi! I’m having a little trouble understanding why svdsolve isn’t working- I can’t seem to find my error. I’m running

```julia
using SparseArrays
using LinearAlgebra
import LinearMaps
import KrylovKit

A = [1 0; 0 1]
Lambda,Phi,Gamma,info = KrylovKit.svdsolve(A, 1, krylovdim=3, tol=1E-3, maxiter=32);

```

and getting

```julia
ERROR: LoadError: ArgumentError: operator and its adjoint are not compatible
Stacktrace:
  [1] initialize(iter::KrylovKit.GKLIterator{Matrix{Int64}, Vector{Int64}, KrylovKit.ModifiedGramSchmidt2}; verbosity::Int64)
    @ KrylovKit ~/.julia/packages/KrylovKit/xccMN/src/factorizations/gkl.jl:195

```

Sorry for the basic question! My eventual hope is to be able to use svdsolve for sparse matrices with bigfloat numbers.

Thanks!

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [November 23, 2024, 1:58pm UTC](https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993/2 "2024-11-23T13:58:25Z")

</div>

I think your call to `svdsolve` is wrong. I think you intended the `1` to mean `howmany` but instead you match this signature:  
`svdsolve(f, m::Int, [howmany = 1, which = :LR, T = Float64]; kwargs...)`  
Where this `m` denotes the number of rows of the operator. Since this is obviously 2 in your case, this likely explains the error you are seeing.

Try:  
`KrylovKit.svdsolve(A, 2, 1, krylovdim=3, tol=1E-3, maxiter=32)`

---

<div class="post-metadata">

**Author:** ![EZ\_Money](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ez_money/32/213637_2.png) [@EZ\_Money](https://discourse.julialang.org/u/EZ_Money)\
**Post date:** [November 24, 2024, 12:20am UTC](https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993/3 "2024-11-24T00:20:26Z")

</div>

That fixed it. Thanks for your answer!

I did a different thing and got an ArgumentError again, so I’m just trying to understand the situation/ figure out why I keep on making this error.

I ran

```julia
B = BigFloat(1)*sparse([1 0; 0 1])
Lambda,Phi,Gamma,info = KrylovKit.svdsolve(B, 2, 1,:SR, krylovdim=3, tol=1e-3, maxiter=32);

```

which gives the error

```julia
julia> ERROR: ArgumentError: operator and its adjoint are not compatible
Stacktrace:
 [1] initialize(iter::KrylovKit.GKLIterator{SparseMatrixCSC{…}, Vector{…}, KrylovKit.ModifiedGramSchmidt2}; verbosity::Int64)
   @ KrylovKit ~/.julia/packages/KrylovKit/xccMN/src/factorizations/gkl.jl:195
 [2] initialize
   @ ~/.julia/packages/KrylovKit/xccMN/src/factorizations/gkl.jl:186 [inlined]
 [3] svdsolve(A::SparseMatrixCSC{…}, x₀::Vector{…}, howmany::Int64, which::Symbol, alg::KrylovKit.GKL{…}; alg_rrule::KrylovKit.Arnoldi{…})
   @ KrylovKit ~/.julia/packages/KrylovKit/xccMN/src/eigsolve/svdsolve.jl:156
 [4] svdsolve(A::SparseMatrixCSC{…}, x₀::Vector{…}, howmany::Int64, which::Symbol, alg::KrylovKit.GKL{…})

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [November 24, 2024, 7:07am UTC](https://discourse.julialang.org/t/krylovkit-svdsolve-not-working/122993/4 "2024-11-24T07:07:14Z")

</div>

If you use an `n::Int` in second position to set the number of rows, then KrylovKit uses `rand(Float64, n)` as starting point. However the application of the matrix then gives a vector with different element type. I suspect that this causes the issue. Try:

`KrylovKit.svdsolve(B, big(rand(2)), 1,:SR, krylovdim=3, tol=1e-3, maxiter=32)`  
Or specify the eltype:  
`KrylovKit.svdsolve(B, 2, 1,:SR, krylovdim=3, tol=1e-3, maxiter=32, T=BigFloat)`
