Skip to content

Commit 53655f9

Browse files
committed
wip
1 parent b222891 commit 53655f9

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/block_krylov_solvers.jl

+22-10
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
101101
end
102102

103103
function ksizeof(attribute)
104-
if isa(attribute, Vector{<:AbstractVector}) && !isempty(attribute)
104+
if isa(attribute, Vector) && isa(eltype(attribute), Vector) && !isempty(attribute)
105105
# A vector of vectors is a vector of pointers in Julia.
106106
# All vectors inside a vector have the same size in Krylov.jl
107107
size_attribute = sizeof(attribute) + length(attribute) * ksizeof(attribute[1])
@@ -111,16 +111,28 @@ function ksizeof(attribute)
111111
return size_attribute
112112
end
113113

114-
function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver})
115-
type = typeof(stats_solver)
116-
nfields = fieldcount(type)
117-
storage = 0
118-
for i = 1:nfields
119-
field_i = getfield(stats_solver, i)
120-
size_i = ksizeof(field_i)
121-
storage += size_i
114+
# function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver, BlockKrylovSolver})
115+
# type = typeof(stats_solver)
116+
# nfields = fieldcount(type)
117+
# storage::Int = 0
118+
# for i = 1:nfields
119+
# field_name = fieldname(type, i)
120+
# field_type::DataType = fieldtype(type, field_name)
121+
# field = getfield(stats_solver, field_name)
122+
# storage += ksizeof(field)::Int
123+
# end
124+
# return storage
125+
# end
126+
127+
@generated function Base.sizeof(stats_solver::T) where T <: Union{KrylovStats, KrylovSolver, BlockKrylovSolver}
128+
nfields = fieldcount(T)
129+
quote
130+
storage = 0
131+
Base.Cartesian.@nexprs $nfields i -> begin
132+
storage += ksizeof(getfield(stats_solver, i))
133+
end
134+
return storage
122135
end
123-
return storage
124136
end
125137

126138
"""

0 commit comments

Comments
 (0)