stdlib: Move SimStat 'unit' and 'datatype' field to Scalar (#970)
These are not general statistic properties and better put as a property of a Scalar value.
This commit is contained in:
@@ -44,23 +44,17 @@ class Statistic(ABC, AbstractStat):
|
|||||||
|
|
||||||
value: Any
|
value: Any
|
||||||
type: Optional[str]
|
type: Optional[str]
|
||||||
unit: Optional[str]
|
|
||||||
description: Optional[str]
|
description: Optional[str]
|
||||||
datatype: Optional[StorageType]
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
value: Any,
|
value: Any,
|
||||||
type: Optional[str] = None,
|
type: Optional[str] = None,
|
||||||
unit: Optional[str] = None,
|
|
||||||
description: Optional[str] = None,
|
description: Optional[str] = None,
|
||||||
datatype: Optional[StorageType] = None,
|
|
||||||
):
|
):
|
||||||
self.value = value
|
self.value = value
|
||||||
self.type = type
|
self.type = type
|
||||||
self.unit = unit
|
|
||||||
self.description = description
|
self.description = description
|
||||||
self.datatype = datatype
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.value)
|
return str(self.value)
|
||||||
@@ -72,6 +66,8 @@ class Scalar(Statistic):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
value: Union[float, int]
|
value: Union[float, int]
|
||||||
|
unit: Optional[str]
|
||||||
|
datatype: Optional[StorageType]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -83,10 +79,10 @@ class Scalar(Statistic):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
value=value,
|
value=value,
|
||||||
type="Scalar",
|
type="Scalar",
|
||||||
unit=unit,
|
|
||||||
description=description,
|
description=description,
|
||||||
datatype=datatype,
|
|
||||||
)
|
)
|
||||||
|
self.unit = unit
|
||||||
|
self.datatype = datatype
|
||||||
|
|
||||||
|
|
||||||
class BaseScalarVector(Statistic):
|
class BaseScalarVector(Statistic):
|
||||||
@@ -100,16 +96,12 @@ class BaseScalarVector(Statistic):
|
|||||||
self,
|
self,
|
||||||
value: Iterable[Union[int, float]],
|
value: Iterable[Union[int, float]],
|
||||||
type: Optional[str] = None,
|
type: Optional[str] = None,
|
||||||
unit: Optional[str] = None,
|
|
||||||
description: Optional[str] = None,
|
description: Optional[str] = None,
|
||||||
datatype: Optional[StorageType] = None,
|
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
value=list(value),
|
value=list(value),
|
||||||
type=type,
|
type=type,
|
||||||
unit=unit,
|
|
||||||
description=description,
|
description=description,
|
||||||
datatype=datatype,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def mean(self) -> float:
|
def mean(self) -> float:
|
||||||
@@ -167,16 +159,12 @@ class Distribution(BaseScalarVector):
|
|||||||
underflow: Optional[int] = None,
|
underflow: Optional[int] = None,
|
||||||
overflow: Optional[int] = None,
|
overflow: Optional[int] = None,
|
||||||
logs: Optional[float] = None,
|
logs: Optional[float] = None,
|
||||||
unit: Optional[str] = None,
|
|
||||||
description: Optional[str] = None,
|
description: Optional[str] = None,
|
||||||
datatype: Optional[StorageType] = None,
|
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
value=value,
|
value=value,
|
||||||
type="Distribution",
|
type="Distribution",
|
||||||
unit=unit,
|
|
||||||
description=description,
|
description=description,
|
||||||
datatype=datatype,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.min = min
|
self.min = min
|
||||||
@@ -211,16 +199,12 @@ class Accumulator(BaseScalarVector):
|
|||||||
min: Union[int, float],
|
min: Union[int, float],
|
||||||
max: Union[int, float],
|
max: Union[int, float],
|
||||||
sum_squared: Optional[int] = None,
|
sum_squared: Optional[int] = None,
|
||||||
unit: Optional[str] = None,
|
|
||||||
description: Optional[str] = None,
|
description: Optional[str] = None,
|
||||||
datatype: Optional[StorageType] = None,
|
|
||||||
):
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
value=value,
|
value=value,
|
||||||
type="Accumulator",
|
type="Accumulator",
|
||||||
unit=unit,
|
|
||||||
description=description,
|
description=description,
|
||||||
datatype=datatype,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self._count = count
|
self._count = count
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ def __get_scaler(statistic: _m5.stats.ScalarInfo) -> Scalar:
|
|||||||
|
|
||||||
|
|
||||||
def __get_distribution(statistic: _m5.stats.DistInfo) -> Distribution:
|
def __get_distribution(statistic: _m5.stats.DistInfo) -> Distribution:
|
||||||
unit = statistic.unit
|
|
||||||
description = statistic.desc
|
description = statistic.desc
|
||||||
value = statistic.values
|
value = statistic.values
|
||||||
bin_size = statistic.bucket_size
|
bin_size = statistic.bucket_size
|
||||||
@@ -167,8 +166,6 @@ def __get_distribution(statistic: _m5.stats.DistInfo) -> Distribution:
|
|||||||
underflow = statistic.underflow
|
underflow = statistic.underflow
|
||||||
overflow = statistic.overflow
|
overflow = statistic.overflow
|
||||||
logs = statistic.logs
|
logs = statistic.logs
|
||||||
# DistInfo uses the C++ `double`.
|
|
||||||
datatype = StorageType["f64"]
|
|
||||||
|
|
||||||
return Distribution(
|
return Distribution(
|
||||||
value=value,
|
value=value,
|
||||||
@@ -181,9 +178,7 @@ def __get_distribution(statistic: _m5.stats.DistInfo) -> Distribution:
|
|||||||
underflow=underflow,
|
underflow=underflow,
|
||||||
overflow=overflow,
|
overflow=overflow,
|
||||||
logs=logs,
|
logs=logs,
|
||||||
unit=unit,
|
|
||||||
description=description,
|
description=description,
|
||||||
datatype=datatype,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user