Hi! I’m having a little trouble understanding why svdsolve isn’t working- I can’t seem to find my error. I’m running
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
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!
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)
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
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> 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{…})
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)