tilus.Script.sum

Contents

tilus.Script.sum

Script.sum(x, *, dim, keepdim=False, out=None)[source]

Sum the elements along a specified dimension.

This instruction computes the sum of the elements in the register tensor x along the specified dimension dim. If keepdim is set to True, the output tensor will have the same number of dimensions as the input tensor, with the specified dimension reduced to size 1. If keepdim is set to False, the output tensor will have the specified dimension removed, resulting in a tensor with one less dimension.

Parameters:
  • x (RegisterTensor) – The register tensor to reduce.

  • dim (int) – The dimension along which to compute the sum. This should be a valid dimension index for the tensor.

  • keepdim (bool, optional) – Whether to keep the reduced dimension in the output tensor. If True, the output tensor will have the same number of dimensions as the input tensor, with the specified dimension reduced to size 1. If False, the output tensor will have the specified dimension removed, resulting in a tensor with one less dimension. Default is False.

  • out (RegisterTensor, optional) – The register tensor to store the result. If not provided, a new register tensor will be allocated.

Returns:

ret – The register tensor containing the sum of the elements along the specified dimension.

Return type:

RegisterTensor