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

**URL:** <https://discourse.julialang.org/t/which-krylov-package-solves-a-x-b-where-x-and-b-can-be-any-vector-like-object/108121>\
**Category:** New to Julia\
**Created:** [December 28, 2023, 10:13am UTC](https://discourse.julialang.org/t/which-krylov-package-solves-a-x-b-where-x-and-b-can-be-any-vector-like-object/108121 "2023-12-28T10:13:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)\
**Post date:** [December 28, 2023, 10:13am UTC](https://discourse.julialang.org/t/which-krylov-package-solves-a-x-b-where-x-and-b-can-be-any-vector-like-object/108121/1 "2023-12-28T10:13:08Z")

</div>

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
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?

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [December 28, 2023, 11:25am UTC](https://discourse.julialang.org/t/which-krylov-package-solves-a-x-b-where-x-and-b-can-be-any-vector-like-object/108121/2 "2023-12-28T11:25:13Z")

</div>

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-repl
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

```
