Shortcuts

torcheval.metrics.functional.sum

torcheval.metrics.functional.sum(input: Tensor, weight: float | Tensor = 1.0) Tensor

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 float nor an int nor a torch.Tensor that 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.)

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources