# Which Krylov package solves A*x=b where x and b can be any "vector-like" object?

Hi, I would like to solve a linear equation `Ax=b` with Krylov method. My unknown “vector” x is a multidimensional array wrapped in a custom type that `<:AbstractArray`, and my `A` operator is just a linear map defined on `x`. Since `x` is not a `AbstractVector`, the `linsolve` function from `KrylovKit` does not seem to work: e.g.,

``````julia> using KrylovKit
julia> b=rand(3,3)
3×3 Matrix{Float64}:
0.132235  0.562757  0.258504
0.745966  0.236753  0.783062
0.674764  0.8032    0.723963

julia> res = linsolve(b) do x
return transpose(x)
end
ERROR: MethodError: no method matching orthogonalize!(::LinearAlgebra.Transpose{Float64, Matrix{Float64}}, ::KrylovKit.OrthonormalBasis{Matrix{Float64}}, ::SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}, ::ModifiedGramSchmidt2)
``````

Here `b` is a 2D array not a vector, `linsolve` does not seem to like it.
So is there a general Krylov package that can solve this toy problem without explicitly “vectorize” inputs and outputs of the linear map?

IIUC, this is searching for `f(X) = b`, where `b` is not vector-like, but rather a `Matrix`.

Either try to define the missing `orthogonalize!` method for your output type,
or convert to a regular array (the `collect` used below) ?

``````julia> using KrylovKit
julia> b = rand(3, 3)
julia> res, info  = linsolve(b) do x
return transpose(x) |> collect
end;
julia> transpose(res) ≈ b
true
``````
1 Like