ReduceOperation
Description
Calculates the sum, maximum or minimum value in a specified dimension and eliminates the dimension.
Formula
- REDUCE_MAX:
Equivalent in PyTorch
intensor.amax(axis)
- Example 1
x shape: [2,3], axis: [0]
x: tensor([[ 1, 18, 17], [16, 10, 1]]) output: tensor([16, 18, 17]) - Example 2
x shape: [2,3,2], axis: [0,1]
x: tensor([[[17, 3], [19, 6], [ 1, 18]], [[ 4, 5], [ 8, 1], [14, 18]]]) output: tensor([19, 18])
- Example 1
- REDUCE_MIN:
Equivalent in PyTorch
intensor.amin(axis)
- Example 1
x shape: [2,3], axis: [0]
x: tensor([[16, 2, 7], [18, 16, 17]]) output: tensor([16, 2, 7]) - Example 2
x shape: [2,3,2], axis: [0,1]
x: tensor([[[ 9, 4], [11, 0], [ 2, 6]], [[ 2, 7], [ 8, 16], [ 5, 3]]]) output: tensor([2, 0])
- Example 1
- REDUCE_SUM:
Equivalent in PyTorch
torch.sum(intensor, axis)
- Example 1
x shape: [2,3], axis: [0]
x: tensor([[-0.9701, -0.8059, 0.2919], [-0.1444, -2.3023, 1.2257]]) output: tensor([-1.1145, -3.1082, 1.5176]) - Example 2
x shape: [2,3,2], axis: [0,1]
x: tensor([[[ 1.4630, -0.3619], [-0.4526, -1.0142], [-0.2883, 0.9334]], [[ 0.7801, -0.1580], [ 0.4843, 1.8145], [ 0.9706, -1.8114]]]) output: tensor([ 2.9571, -0.5976])
- Example 1
Definition
struct ReduceParam {
enum ReduceType {
REDUCE_UNDEFINED = 0,
REDUCE_MAX,
REDUCE_MIN,
REDUCE_SUM,
};
ReduceType reduceType = REDUCE_UNDEFINED;
SVector<int64_t> axis;
uint8_t rsv[8] = {0};
};
Parameters
Member |
Type |
Default Value |
Description |
|---|---|---|---|
reduceType |
ReduceType |
REDUCE_UNDEFINED |
Calculation type. The following options are supported:
|
axis |
SVector<int64_t> |
{} |
Axis (dimension).
|
rsv[8] |
uint8_t |
{0} |
Reserved |
Input
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
x |
[-1,...,-1] The value -1 indicates that the size of the current dimension is not restricted. |
|
ND |
Input tensor. |
Output
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
output |
Eliminates the dimension required by axis based on the dimension of input x. |
|
ND |
Output tensor. |
Restrictions
- axis cannot be empty and its length must be less than or equal to the dimension of input x.
- The dimension of each element in axis must be less than x and greater than or equal to 0.
- reduceType must be REDUCE_MAX, REDUCE_MIN, or REDUCE_SUM.