JuliaSmoothOptimizers / Krylov.jl

A Julia Basket of Hand-Picked Krylov Methods
Other
349 stars 51 forks source link

StaticArrays support #766

Open gdalle opened 1 year ago

gdalle commented 1 year ago

At the moment, the solvers fail on StaticArrays

julia> using Krylov, StaticArrays

julia> A = rand(2, 2)
2×2 Matrix{Float64}:
 0.175316  0.379652
 0.908308  0.655592

julia> b = SVector{2}(rand(2))
2-element SVector{2, Float64} with indices SOneTo(2):
 0.4292733187710226
 0.6223773606304001

julia> A \ b
2-element Vector{Float64}:
 -0.19634658574195155
  1.2213703847547805

julia> gmres(A, b)
ERROR: MethodError: Cannot `convert` an object of type UndefInitializer to an object of type Float64

Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number
   @ Base number.jl:6
  convert(::Type{T}, ::Number) where T<:Number
   @ Base number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number
   @ Base twiceprecision.jl:273
  ...

Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:88 [inlined]
  [2] convert_ntuple
    @ ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:84 [inlined]
  [3] SVector{2, Float64}(x::Tuple{UndefInitializer, Int64})
    @ StaticArraysCore ~/.julia/packages/StaticArraysCore/P6PH7/src/StaticArraysCore.jl:120
  [4] SVector{2, Float64}(::UndefInitializer, ::Vararg{Any})
    @ StaticArrays ~/.julia/packages/StaticArrays/9KYrc/src/convert.jl:165
  [5] GmresSolver(m::Int64, n::Int64, memory::Int64, S::Type{SVector{2, Float64}})
    @ Krylov ~/.julia/packages/Krylov/Iuavd/src/krylov_solvers.jl:1549
  [6] GmresSolver(A::Matrix{Float64}, b::SVector{2, Float64}, memory::Int64)
    @ Krylov ~/.julia/packages/Krylov/Iuavd/src/krylov_solvers.jl:1567
  [7] gmres(A::Matrix{Float64}, b::SVector{2, Float64}; memory::Int64, M::LinearAlgebra.UniformScaling{Bool}, N::LinearAlgebra.UniformScaling{Bool}, ldiv::Bool, restart::Bool, reorthogonalization::Bool, atol::Float64, rtol::Float64, itmax::Int64, timemax::Float64, verbose::Int64, history::Bool, callback::Krylov.var"#164#171", iostream::Core.CoreSTDOUT)
    @ Krylov ~/.julia/packages/Krylov/Iuavd/src/gmres.jl:121
  [8] gmres(A::Matrix{Float64}, b::SVector{2, Float64})
    @ Krylov ~/.julia/packages/Krylov/Iuavd/src/gmres.jl:119
  [9] top-level scope
    @ REPL[7]:1