asc2.reduce_sum
- asc2.reduce_sum(input: LocalTensor, *dims: int, keep_dims: bool = False) LocalTensor
- asc2.reduce_sum(input: LocalTensor) PlainValue
Returns the sum of each row of the
inputtensor in the given dimensionsdims.Dimensions
dimsare squeezed, resulting the output tensor having fewer dimensions than input, unlesskeep_dims=Trueis provided. When dimension is not specified, the entire tensor is reduced to a single scalar value.The supported data types for the input are:
int32,int64,float32. When reducing to a single scalar value, the supported data types are:int64,float16,float32.- Parameters:
input – The input tensor
dims – Optional, dimensions to reduce, should be in range of [0..len(input.shape)-1]
keep_dims – If set to True, then reduced dimensions are kept in the result shape with size of 1
- Raises:
TypeError – If input is not a
LocalTensor, keep_dims is not a bool, or dims contains non-integer valuesRuntimeError – If input dtype is not supported, or if
dimsexplicitly lists all dimensions
Examples
Reduce tensor by first (outermost) dimension, resulting tensor having the shape [256], each element is sum of 128 elements in corresponding column:
input = asc2.copy_in(x, [0, 0], [128, 256]) result = asc2.reduce_sum(input, 0)
Compute total sum of all numbers in tensor, returns single scalar value:
input = asc2.copy_in(x, [0, 0], [256, 256]) result = asc2.reduce_sum(input)
This function can also be called as a member function on
LocalTensor, asinput.sum(...)instead ofreduce_sum(input, ...).