Skip to content

Commit

Permalink
Fix the sizeof of a vector of vector
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 11, 2022
1 parent 8a2978b commit ea73605
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,10 @@ for (KS, fun, nsol, nA, nAt, warm_start) in [
end

function ksizeof(attribute)
if isa(attribute, AbstractVector) && !isempty(attribute)
if isa(attribute, Vector{<:AbstractVector}) && !isempty(attribute)
# A vector of vector is a vector of pointers in Julia.
# All vectors inside a vector have the same size in Krylov.jl
size_attribute = length(attribute) * ksizeof(attribute[1])
size_attribute = sizeof(attribute) + length(attribute) * ksizeof(attribute[1])
else
size_attribute = sizeof(attribute)
end
Expand Down Expand Up @@ -1938,9 +1939,9 @@ function show(io :: IO, solver :: KrylovSolver{T,FC,S}; show_stats :: Bool=true)
field_i = getfield(solver, name_i)
size_i = ksizeof(field_i)
if (name_i in [:w̅, :w̄, :d̅]) && (VERSION < v"1.8.0-DEV")
Printf.format(io, format2, string(name_i), type_i, format_bytes(size_i))
(size_i 0) && Printf.format(io, format2, string(name_i), type_i, format_bytes(size_i))
else
Printf.format(io, format, string(name_i), type_i, format_bytes(size_i))
(size_i 0) && Printf.format(io, format, string(name_i), type_i, format_bytes(size_i))
end
end
@printf(io, "└%s┴%s┴%s┘\n",""^l1,""^l2,""^l3)
Expand Down
3 changes: 3 additions & 0 deletions test/test_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ function test_solvers(FC)
@test mapreduce(x -> length(x) - mapreduce(y -> occursin(y, x), |, ["","",""]) == len_col1, &, str2[1:3:end-2])
@test mapreduce(x -> length(x) - mapreduce(y -> occursin(y, x), |, ["","",""]) == len_col2, &, str2[2:3:end-1])
@test mapreduce(x -> length(x) - mapreduce(y -> occursin(y, x), |, ["","",""]) == len_col3, &, str2[3:3:end])

# Code coverage
show(io, solver, show_stats=true)
end
end
end
Expand Down

0 comments on commit ea73605

Please sign in to comment.