def as_number(cls, obj: TScalar) -> Union[int, float]: if isinstance(obj, torch.Tensor): obj_as_number: Union[int, float] = obj.item() else: obj_as_number = obj # type: ignore assert isinstance(obj_as_number, int) or isinstance(obj_as_number, float) return obj_as_number
def __init__(self, sum_: TScalar = 0): if isinstance(sum_, torch.Tensor): self._sum = sum_.item() else: assert isinstance(sum_, (int, float)) self._sum = sum_