Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 31, 2024
1 parent bd6cf25 commit 302e95a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/block_krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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

"""
Expand Down

0 comments on commit 302e95a

Please sign in to comment.