Gather

Description

It is an indexing operation that indexes into the inputΒ dataΒ along a single (specified) axis. Each entry inΒ indicesΒ produces aΒ r-1Β dimensional slice of the input tensor. The entire operation produces, conceptually, aΒ q-dimensional tensor ofΒ r-1Β dimensional slices, which is arranged into aΒ qΒ +Β (r-1)-dimensional tensor, with theΒ qΒ dimensions taking the place of the originalΒ axisΒ that is being indexed into.

 

 

GivenΒ dataΒ tensor of rank r >= 1, andΒ indicesΒ tensor of rank q, gather entries of the axis dimension ofΒ dataΒ (by default outer-most one as axis=0) indexed byΒ indices, and concatenates them in an output tensor of rank q + (r – 1).

The following few examples illustrate howΒ GatherΒ works for specific shapes ofΒ data,Β indices, and given value ofΒ axis :

 

data shape indices shape axis output shape output equation
(P, Q) ( ) (a scalar) 0 (Q) output[q] = data[indices, q]
(P, Q, R) ( ) (a scalar) 1 (P, R) output[p, r] = data[p, indices, r]
(P, Q) (R, S) 0 (R, S, Q) output[r, s, q] = data[ [indices[r, s], q]
(P, Q) (R, S) 1 (P, R, S) output[p, r, s] = data[ p, indices[r, s]]

Β 

Input parameters

 

specified_outputs_name :Β array, this parameter lets you manually assign custom names to the output tensors of a node.

Β Graphs in :Β cluster, ONNX model architecture.

Β dataΒ (heterogeneous) – T :Β object, tensor of rank r >= 1.
Β indices (heterogeneous) – Tind : object, tensor of int32/int64 indices, of any rank q. All index values are expected to be within bounds [-s, s-1] along axis of size s. It is an error if any of the index values are out of bounds.

Β Parameters :Β cluster,

axis : integer, which axis to gather on. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(data).
Default value β€œ0”.
Β training?Β :Β boolean, whether the layer is in training mode (can store data for backward).
Default value β€œTrue”.
Β lda coeff :Β float, defines the coefficient by which the loss derivative will be multiplied before being sent to the previous layer (since during the backward run we go backwards).
Default value β€œ1”.

Β name (optional) :Β string, name of the node.

Output parameters

 

Β outputΒ (heterogeneous) – T :Β object, tensor of rank q + (r – 1).

Type Constraints

T in (tensor(bfloat16),Β tensor(bool),Β tensor(complex128),Β tensor(complex64),Β tensor(double),Β tensor(float),Β tensor(float16),Β 
tensor(int16),Β tensor(int32),Β tensor(int64),Β tensor(int8),Β tensor(string),Β tensor(uint16),Β tensor(uint32),Β tensor(uint64),Β tensor(uint8)) : Constrain input and output types to any tensor type.

Tind in (tensor(int32),Β tensor(int64)) : Constrain indices to integer types.

Example

All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install Deep Learning library to run it).
Table of Contents