Rate this Page

torch.foreach.add#

torch.foreach.add(inputs: TensorList, other: Scalar, /) tuple[Tensor, ...][source]#
torch.foreach.add(inputs: TensorList, other: ScalarList, /) tuple[Tensor, ...]
torch.foreach.add(inputs: TensorList, other: Tensor, /, *, alpha: Scalar) tuple[Tensor, ...]
torch.foreach.add(inputs: TensorList, other: TensorList, /, *, alpha: Scalar = 1) tuple[Tensor, ...]

Applies torch.add() to every tensor in inputs.

This is semantically equivalent to applying torch.add() independently at every list position. Does not mutate its arguments and returns a tuple of result tensors.

Tensor-list arguments must be non-empty. Corresponding tensor or scalar lists must have the same length. An accelerated multi-tensor implementation is used only when supported by the inputs; otherwise the operation falls back to per-tensor execution.

A shared Tensor operand must be a 0-D scalar tensor.

For a shared 0-D tensor, pass alpha explicitly, including when its value is 1, to select the Tensor overload. Omitting alpha may convert the tensor to a host scalar.

Parameters:
  • inputs (list or tuple of Tensor) – tensors to transform.

  • other (Number, list or tuple of Number, or list or tuple of Tensor, or Tensor) – operand shared across positions or supplied per position.

  • alpha (Number, optional) – supported only when other is a tensor list or a shared 0-D scalar tensor. Default: 1.

Returns:

a tuple containing one result tensor for each input tensor.