stdlib: Add SparseHist to PyStats

This is inclusive of tests to ensure they have implemented correctly.

Change-Id: I5c84d5ffdb7b914936cfd86ca012a7b141eeaf42
This commit is contained in:
Bobby R. Bruce
2024-03-27 10:06:16 -07:00
parent b5e8804cd4
commit 178679cbfd
9 changed files with 251 additions and 0 deletions

View File

@@ -140,6 +140,8 @@ def __get_statistic(statistic: _m5.stats.Info) -> Optional[Statistic]:
return __get_vector(statistic)
elif isinstance(statistic, _m5.stats.Vector2dInfo):
return __get_vector2d(statistic)
elif isinstance(statistic, _m5.stats.SparseHistInfo):
return __get_sparse_hist(statistic)
return None
@@ -268,6 +270,24 @@ def __get_vector2d(statistic: _m5.stats.Vector2dInfo) -> Vector2d:
return Vector2d(value=vector_rep, type="Vector2d", description=description)
def __get_sparse_hist(statistic: _m5.stats.SparseHistInfo) -> SparseHist:
description = statistic.desc
value = statistic.values
parsed_values = {}
for val in value:
parsed_values[val] = Scalar(
value=value[val],
unit=statistic.unit,
datatype=StorageType["f64"],
)
return SparseHist(
value=parsed_values,
description=description,
)
def _prepare_stats(group: _m5.stats.Group):
"""
Prepares the statistics for dumping.