Skip to main content

ISliceLayer

Struct ISliceLayer 

Source
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

Source

pub fn setStart(self: Pin<&mut ISliceLayer>, start: &Dims64)

Set the start offset that the slice layer uses to create the output slice.

  • start The 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]

Source

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]

Source

pub fn setSize(self: Pin<&mut ISliceLayer>, size: &Dims64)

Set the dimensions of the output slice.

  • size The 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]

Source

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]

Source

pub fn setStride(self: Pin<&mut ISliceLayer>, stride: &Dims64)

Set the stride for computing the output slice data.

  • stride The 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]

Source

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]

Source

pub fn setMode(self: Pin<&mut ISliceLayer>, mode: SampleMode)

Set the slice mode.

See [getMode()]

Source

pub fn getMode(self: &ISliceLayer) -> SampleMode

Get the slice mode.

See [setMode()]

Source

pub fn setAxes(self: Pin<&mut ISliceLayer>, axes: &Dims64)

Set the axes for this ISliceLayer.

  • axes The 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]

Source

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]

Trait Implementations§

Source§

impl AsLayer for ISliceLayer

Source§

fn as_layer(&self) -> &ILayer

Source§

fn as_layer_pin_mut(&mut self) -> Pin<&mut ILayer>

Source§

impl AsLayerTyped for ISliceLayer

Source§

const TYPE: LayerType = LayerType::kSLICE

Source§

impl AsRef<ILayer> for ISliceLayer

Source§

fn as_ref(self: &ISliceLayer) -> &ILayer

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl ExternType for ISliceLayer

Source§

type Id = (n, v, i, n, f, e, r, _1, (), I, S, l, i, c, e, L, a, y, e, r)

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

type Kind = Opaque

Source§

impl MakeCppStorage for ISliceLayer

Source§

unsafe fn allocate_uninitialized_cpp_storage() -> *mut ISliceLayer

Allocates heap space for this type in C++ and return a pointer to that space, but do not initialize that space (i.e. do not yet call a constructor). Read more
Source§

unsafe fn free_uninitialized_cpp_storage(arg0: *mut ISliceLayer)

Frees a C++ allocation which has not yet had a constructor called. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.