torcheval.metrics.functional.sum¶
-
torcheval.metrics.functional.sum(input: Tensor, weight: Union[float, Tensor] = 1.0) Tensor[source]¶ Compute weighted sum. When weight is not provided, it calculates the unweighted sum. Its class version is
torcheval.metrics.Sum.Parameters: - input (Tensor) – Tensor of input values.
- weight (optional) – Float or Int or Tensor of input weights. It is default to 1.0. If weight is a Tensor, its size should match the input tensor size.
Raises: ValueError – If value of weight is neither a
floatnor anintnor atorch.Tensorthat matches the input tensor size.Examples:
>>> import torch >>> from torcheval.metrics.functional import sum >>> sum(torch.tensor([2, 3])) tensor(5.) >>> sum(torch.tensor([2, 3]), torch.tensor([0.1, 0.6])) tensor(2.) >>> sum(torch.tensor([2, 3]), 0.5) tensor(2.5) >>> sum(torch.tensor([2, 3]), 2) tensor(10.)