IndexAddOperation

Description

Adds a value to a specified index of a fixed dimension.

Figure 1 IndexAddOperation

Definition

struct IndexAddParam {
    enum IndexType {
        INDEX_UNDEFINED = 0,
        INDEX_ADD,
        INDEX_ADD_VALID, 
    };
    IndexType indexType = INDEX_UNDEFINED;
    int64_t axis = 0;
    uint8_t rsv[16] = {0};
};

Parameters

Member

Type

Default Value

Description

indexType

IndexType

INDEX_UNDEFINED

Operation type.

  • INDEX_UNDEFINED: undefined.
  • INDEX_ADD: addition.
  • INDEX_ADD_VALID: addition within the valid length. Atlas inference products: not supported.

axis

int64_t

0

Axis of the input tensor plus the updates value.

  • When indexType is set to INDEX_ADD, the value can be a negative number. The value range is [-varDimNum, varDimNum - 1]. varDimNum is the number of dimensions of input tensor 0.
  • When indexType is set to INDEX_ADD_VALID, the value can only be 0.

rsv[16]

uint8_t

{0}

Reserved

Input and Output (INDEX_ADD)

Parameter

Dimension

Data Type

Format

Description

var

[d_0, ..., d_n]

float16

ND

Input tensor. Augend. The input is zero to which addened is added in place as the output.

indices

[d_x]

int32

ND

Input tensor. Specified index of a fixed dimension. d_min = min(d_x, d_axis). The value range is [0, d_min). The first d_min values must be unique.

updates

[d_0, ..., d_n]

float16

ND

Input tensor. Addend, which is added to var based on the value of indices. The number of dimensions is the same as that of var. The dimension of the axis index is d_x, that is, d_axis = = d_x.

alpha

[1]

float16

ND

Input tensor. Accumulation times.

output

[d_0, ..., d_n]

float16

ND

Output tensor. It is the same as var. That is, they have the same attributes, such as the data type, data format, and address.

min(x, y) indicates that the smaller value between x and y is used.

d_axis indicates the size of var, updates, and output in the dimension whose index is axis. That is, if axis is 0, d_axis corresponds to the size d_0 of the 0th dimension.

Input and Output (INDEX_ADD_VALID)

Parameter

Dimension

Data Type

Format

Description

var

[d_1, d_2]

float16

ND

Input tensor. Augend. The input is zero to which addened is added in place as the output.

indices

[d_0]

int32

ND

Input tensor. Specified index of a fixed dimension. Specified index of a fixed dimension. The value range is [0, d_1).

updates

[d_0, d_2]

float16

ND

Input tensor. Addend, which is added to var based on the value of indices.

validIndicesNum

[1]

int32

ND

Input tensor. Valid length of indices. The value range is [0, d_0].

output

[d_1, d_2]

float16

ND

Output tensor. It is the same as var. That is, they have the same attributes, such as the data type, data format, and address.

The value range of d_2 is (0, 8192].

API Calling Example

  • indexType = INDEX_ADD
    • Input

      indexType = 0

      axis = 0

      var =
      [[ 1, 1, 1 ],
       [ 1, 1, 1],
       [ 1, 1, 1],
       [ 1, 1, 1],
       [ 1, 1, 1]],

      indices = torch.tensor[0, 4, 2]

      updates =

      [[ 1, 2, 3 ],
       [ 4, 5, 6],
       [ 7, 8, 9]]

      alpha = 1

    • Output
      output =
      [[  2,   3,   4],
       [  1,   1,   1],
       [  8,   9,  10],
       [  1,   1,   1],
       [  5,   6,   7]]
  • indexType = INDEX_ADD_VALID
    • Input

      indexType = 1

      axis = 0

      var =

      [[ 0, 0, 0 ],
       [ 0, 0, 0],
       [ 0, 0, 0],
       [ 0, 0, 0],
       [ 0, 0, 0]]

      indices = {[0, 2, 2, -1, -1]}

      updates =

      [[ 0, 1, 2 ],
       [ 1, 2, 3],
       [ 2, 3, 4],
       [5, 6, 7],
       [6, 7, 8]]

      validIndicesNum = {[3]}

    • Output
      output =
      [[  0,   1,   2],
       [  0,   0,   0],
       [  3,   5,  7],
       [  0,   0,   0],
       [  0,   0,   0]]