Roll¶
Versioned name: Roll-7
Category: Data movement
Short description: The Roll operation shifts elements of a tensor along specified axes.
Detailed description: Roll produces a tensor with the same shape as the first input tensor and with elements shifted along dimensions specified in the axes tensor. The shift size is specified in the shift input tensor. Elements that are shifted beyond the last position will be added in the same order starting from the first position.
Example 1. Roll output with shift = 1, axes = 0:
data = [[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]]
output = [[10, 11, 12],
[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]]
Example 2. Roll output with shift = [-1, 2], axes = [0, 1]:
data = [[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]]
output = [[ 5, 6, 4],
[ 8, 9, 7],
[11, 12, 10],
[ 2, 3, 1]]
Example 3. Roll output with shift = [1, 2, 1], axes = [0, 1, 0]:
data = [[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]]
output = [[ 8, 9, 7],
[11, 12, 10],
[ 2, 3, 1],
[ 5, 6, 4]]
Attributes
No attributes available.
Inputs:
1:
dataa tensor of type T. Required.2: a
shiftscalar or 1D tensor of type T_IND_1. Specifies the number of places by which the elements of thedatatensor are shifted. Ifshiftis a scalar, each dimension specified in theaxestensor are rolled by the sameshiftvalue. Ifshiftis a 1D tensor,axesmust be a 1D tensor of the same size, and each dimension fromaxestensor are rolled by the corresponding value from theshifttensor. If the value ofshiftis positive, elements are shifted positively (towards larger indices). Otherwise, elements are shifted negatively (towards smaller indices). Required.3:
axesa scalar or 1D tensor of type T_IND_2. Specifies axes along which elements are shifted. If the same axis is referenced more than once, the total shift for that axis will be the sum of all the shifts that belong to that axis. Ifaxeshas negative value, axis index will be calculated using the formula:N_dims + axis, whereN_dims- total number of dimensions in thedatatensor,axis- negative axis index from theaxestensor. Required.
Outputs:
1: output tensor with shape and type equal to the
datatensor.
Types
T: any supported type.
T_IND_1:
int32orint64.T_IND_2:
int32orint64.
Example
Example 1: “shift” and “axes” are 1D tensors.
<layer ... type="Roll">
<input>
<port id="0">
<dim>3</dim>
<dim>10</dim>
<dim>100</dim>
<dim>200</dim>
</port>
<port id="1">
<dim>2</dim>
</port>
<port id="2">
<dim>2</dim> <!-- shifting along specified axes with the corresponding shift values -->
</port>
</input>
<output>
<port id="0">
<dim>3</dim>
<dim>10</dim>
<dim>100</dim>
<dim>200</dim>
</port>
</output>
</layer>
Example 2: “shift” value is a scalar and multiple axes are specified.
<layer ... type="Roll">
<input>
<port id="0">
<dim>3</dim>
<dim>10</dim>
<dim>100</dim>
<dim>200</dim>
</port>
<port id="1">
<dim>1</dim>
</port>
<port id="2">
<dim>2</dim> <!-- shifting along specified axes with the same shift value -->
</port>
</input>
<output>
<port id="0">
<dim>3</dim>
<dim>10</dim>
<dim>100</dim>
<dim>200</dim>
</port>
</output>
</layer>