From 302e95af22e7afb4f2a507730923f52b545b8db0 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Wed, 22 May 2024 08:23:03 -0400 Subject: [PATCH] wip --- src/block_krylov_solvers.jl | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/block_krylov_solvers.jl b/src/block_krylov_solvers.jl index a1e8db13a..20b78efc4 100644 --- a/src/block_krylov_solvers.jl +++ b/src/block_krylov_solvers.jl @@ -103,7 +103,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]) @@ -113,16 +113,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 """