Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of sizeof #50

Open
amontoison opened this issue Oct 7, 2022 · 0 comments
Open

Implementation of sizeof #50

amontoison opened this issue Oct 7, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@amontoison
Copy link
Member

amontoison commented Oct 7, 2022

It could be relevant to know the storage used by a stats or a solver sometimes.
I implemented my own function in Krylov.jl but it can be used here too for optimization solvers.

function ksizeof(attribute)
  if isa(attribute, AbstractVector) && !isempty(attribute)
    # All vectors inside a vector have the same size in Krylov.jl
    size_attribute = length(attribute) * ksizeof(attribute[1])
  else
    size_attribute = sizeof(attribute)
  end
  return size_attribute
end

function sizeof(stats_solver :: Union{KrylovStats, KrylovSolver})
  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
  end
  return storage
end
@amontoison amontoison added the enhancement New feature or request label Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant