pub struct ISliceLayer { /* private fields */ }Expand description
Slices an input tensor into an output tensor based on the offset and strides.
The slice layer has two variants, static and dynamic. Static slice specifies the start, size, and stride dimensions at layer creation time via Dims and can use the get/set accessor functions of the ISliceLayer. Static slice layers can also optionally specify axes through the get/set accessor functions of the ISliceLayer. Dynamic slice specifies one or more of start, size, stride, or axes as ITensors, by using ILayer::setInput to add a second, third, fourth, or sixth input respectively. The corresponding Dims are used if an input is missing or null.
An application can determine if the ISliceLayer has a dynamic output shape based on whether the size or axes input is present and non-null.
The slice layer selects for each dimension a start location from within the input tensor, and copies elements to the output tensor using the specified stride across the input tensor. Start, size, and stride tensors must be 1D tensors of type Int32 or Int64 if not specified via Dims.
An example of using slice on a tensor: input = {{0, 2, 4}, {1, 3, 5}} start = {1, 0} size = {1, 2} stride = {1, 2} output = {{1, 5}}
If axes are provided then starts, ends, and strides must have the same length as axes and specifies a subset of dimensions to slice. If axes are not provided, starts, ends, and strides must be of the same length as the rank of the input tensor.
An example of using slice on a tensor with axes specified: input = {{0, 2, 4}, {1, 3, 5}} start = {1} size = {2} stride = {1} axes = {1} output = {{2, 4}, {3, 5}}
When the sampleMode is kCLAMP or kREFLECT, for each input dimension, if its size is 0 then the corresponding output dimension must be 0 too.
When the sampleMode is kFILL, the fifth input to the slice layer is used to determine the value to fill in out-of-bound indices. It is an error to specify the fifth input in any other sampleMode.
A slice layer can produce a shape tensor if the following conditions are met:
- start, size, and stride are build time constants, either as static Dims or as constant input tensors.
- axes, if provided, are build time constants, either as static Dims or as a constant input tensor.
- The number of elements in the output tensor does not exceed 2 * Dims::MAX_DIMS.
The input tensor is a shape tensor if the output is a shape tensor.
The following constraints must be satisfied to execute this layer on DLA:
- start, size, and stride are build time constants, either as static Dims or as constant input tensors.
- axes, if provided, are build time constants, either as static Dims or as a constant input tensor.
- sampleMode is kDEFAULT, kWRAP, or kFILL.
- Strides are 1 for all dimensions.
- Slicing is not performed on the first dimension.
- The input tensor has four dimensions.
- For kFILL sliceMode, the fill value input is a scalar output of an IConstantLayer with value 0 that is not consumed by any other layer.
Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
Implementations§
Source§impl ISliceLayer
impl ISliceLayer
Sourcepub fn setStart(self: Pin<&mut ISliceLayer>, start: &Dims64)
pub fn setStart(self: Pin<&mut ISliceLayer>, start: &Dims64)
Set the start offset that the slice layer uses to create the output slice.
startThe start offset to read data from the input tensor.
If a second input had been used to create this layer, that input is reset to null by this method.
See [getStart]
Sourcepub fn getStart(self: &ISliceLayer) -> Dims64
pub fn getStart(self: &ISliceLayer) -> Dims64
Get the start offset for the slice layer.
The start offset, or an invalid Dims structure.
If the second input is present and non-null, this function returns a Dims with nbDims = -1.
See [setStart]
Sourcepub fn setSize(self: Pin<&mut ISliceLayer>, size: &Dims64)
pub fn setSize(self: Pin<&mut ISliceLayer>, size: &Dims64)
Set the dimensions of the output slice.
sizeThe dimensions of the output slice.
If a third input had been used to create this layer, that input is reset to null by this method.
See [getSize]
Sourcepub fn getSize(self: &ISliceLayer) -> Dims64
pub fn getSize(self: &ISliceLayer) -> Dims64
Get dimensions of the output slice.
The output dimension, or an invalid Dims structure.
If the third input is present and non-null, this function returns a Dims with nbDims = -1.
See [setSize]
Sourcepub fn setStride(self: Pin<&mut ISliceLayer>, stride: &Dims64)
pub fn setStride(self: Pin<&mut ISliceLayer>, stride: &Dims64)
Set the stride for computing the output slice data.
strideThe dimensions of the stride to compute the values to store in the output slice.
If a fourth input had been used to create this layer, that input is reset to null by this method.
See [getStride]
Sourcepub fn getStride(self: &ISliceLayer) -> Dims64
pub fn getStride(self: &ISliceLayer) -> Dims64
Get the stride for the output slice.
The slicing stride, or an invalid Dims structure.
If the fourth input is present and non-null, this function returns a Dims with nbDims = -1.
See [setStride]
Sourcepub fn setMode(self: Pin<&mut ISliceLayer>, mode: SampleMode)
pub fn setMode(self: Pin<&mut ISliceLayer>, mode: SampleMode)
Set the slice mode.
See [getMode()]
Sourcepub fn getMode(self: &ISliceLayer) -> SampleMode
pub fn getMode(self: &ISliceLayer) -> SampleMode
Get the slice mode.
See [setMode()]
Sourcepub fn setAxes(self: Pin<&mut ISliceLayer>, axes: &Dims64)
pub fn setAxes(self: Pin<&mut ISliceLayer>, axes: &Dims64)
Set the axes for this ISliceLayer.
axesThe axes on which the starts, ends, and strides parameters of the slice apply to.
If a sixth input had been used to create this layer, that input is reset to null by this method.
See [getAxes]
Sourcepub fn getAxes(self: &ISliceLayer) -> Dims64
pub fn getAxes(self: &ISliceLayer) -> Dims64
Get the axes for this ISliceLayer.
The axes on which the starts, ends, and strides parameters of this slice apply to.
If the sixth input is present and non-null, this function returns a Dims with nbDims = -1.
See [setAxes]