diff --git a/src/block_krylov_solvers.jl b/src/block_krylov_solvers.jl index c6c128aeb..602b73aa3 100644 --- a/src/block_krylov_solvers.jl +++ b/src/block_krylov_solvers.jl @@ -99,7 +99,7 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [ end function ksizeof(attribute) - if isa(attribute, Vector{<:AbstractVector}) && !isempty(attribute) + if isa(attribute, Vector) && isa(eltype(attribute), Vector) && !isempty(attribute) # A vector of vectors is a vector of pointers in Julia. # All vectors inside a vector have the same size in Krylov.jl size_attribute = sizeof(attribute) + length(attribute) * ksizeof(attribute[1]) @@ -109,16 +109,28 @@ function ksizeof(attribute) return size_attribute end -function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver}) - type = typeof(stats_solver) - nfields = fieldcount(type) - storage = 0 - for i = 1:nfields - field_i = getfield(stats_solver, i) - size_i = ksizeof(field_i) - storage += size_i +# function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver}) +# type = typeof(stats_solver) +# nfields = fieldcount(type) +# storage::Int = 0 +# for i = 1:nfields +# field_name = fieldname(type, i) +# field_type::DataType = fieldtype(type, field_name) +# field = getfield(stats_solver, field_name) +# storage += ksizeof(field)::Int +# end +# return storage +# end + +@generated function Base.sizeof(stats_solver::T) where T <: Union{KrylovStats, KrylovSolver, BlockKrylovSolver} + nfields = fieldcount(T) + quote + storage = 0 + Base.Cartesian.@nexprs $nfields i -> begin + storage += ksizeof(getfield(stats_solver, i)) + end + return storage end - return storage end """