@@ -101,7 +101,7 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
101
101
end
102
102
103
103
function ksizeof (attribute)
104
- if isa (attribute, Vector{ <: AbstractVector } ) && ! isempty (attribute)
104
+ if isa (attribute, Vector) && isa ( eltype (attribute), Vector ) && ! isempty (attribute)
105
105
# A vector of vectors is a vector of pointers in Julia.
106
106
# All vectors inside a vector have the same size in Krylov.jl
107
107
size_attribute = sizeof (attribute) + length (attribute) * ksizeof (attribute[1 ])
@@ -111,16 +111,28 @@ function ksizeof(attribute)
111
111
return size_attribute
112
112
end
113
113
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
122
135
end
123
- return storage
124
136
end
125
137
126
138
"""
0 commit comments