Skip to main content

IGatherLayer

Struct IGatherLayer 

Source
pub struct IGatherLayer { /* private fields */ }
Expand description

IGatherLayer

A Gather layer in a network definition. Supports several kinds of gathering.

The Gather layer has two input tensors, Data and Indices, and an output tensor Output. Additionally, there are three parameters: mode, nbElementwiseDims, and axis that control how the indices are interpreted.

  • Data is a tensor of rank r >= 1 that stores the values to be gathered in Output.
  • Indices is a tensor of rank q that determines which locations in Data to gather.
  • GatherMode::kDEFAULT: q >= 0
  • GatherMode::kND: q >= 1 and the last dimension of Indices must be a build time constant.
  • GatherMode::kELEMENT: q = r
  • Output stores the gathered results. Its rank s depends on the mode:
  • GatherMode::kDEFAULT: s = q + r - 1 - nbElementwiseDims
  • GatherMode::kND: s = q + r - indices.d[q-1] - 1 - nbElementwiseDims
  • GatherMode::kELEMENT: s = q = r.

The dimensions of the output likewise depends on the mode:

GatherMode::kDEFAULT:

First nbElementwiseDims of output are computed by applying broadcast rules to first nbElementwiseDims of indices and data. Note that nbElementwiseDims <= 1. Rest of dimensions are computed by copying dimensions of Data, and replacing the dimension for axis gatherAxis with the dimensions of indices.

GatherMode::kND: If indices.d[q-1] = r - nbElementwiseDims output.d = [indices.d[0], … , indices.d[q-2]] Else if indices.d[q-1] < r - nbElementwiseDims output.d = [indices.d[0], … , indices.d[q-1], data.d[nbElementwiseDims + indices.d[q-1] + q], data.d[r-1]] Else This is build time error

GatherMode::kELEMENT: The output dimensions match the dimensions of the indices tensor.

The types of Data and Output must be the same, and Indices shall be DataType::kINT32 or DataType::kINT64.

How the elements of Data are gathered depends on the mode:

GatherMode::kDEFAULT: Each index in indices is used to index Data along axis gatherAxis.

GatherMode::kND: Indices is a rank q integer tensor, best thought of as a rank (q-1) tensor of indices into data, where each element defines a slice of data The operation can be formulated as output[i_1, …, i_{q-1}] = data[indices[i_1, …, i_{q-1}]]

GatherMode::kELEMENT:

Here “axis” denotes the result of getGatherAxis(). For each element X of indices: Let J denote a sequence for the subscripts of X Let K = sequence J with element [axis] replaced by X output[J] = data[K]

The handling of nbElementWiseDims depends on the mode:

  • GatherMode::kDEFAULT: nbElementWiseDims <= 1. Broadcast is supported across the elementwise dimension if present.
  • GatherMode::kND: 0 <= nbElementWiseDims < rank(Data)-1. Broadcast is not supported across the elementwise dimensions.
  • GatherMode::kELEMENT: nbElementWiseDims = 0

Notes:

  • For modes GatherMode::kND and GatherMode::kELEMENT, the first nbElementWiseDims dimensions of data and index must be equal. If not, an error will be reported at build time or run time.
  • If an axis of Data has dynamic length, using a negative index for it has undefined behavior.
  • No DLA support
  • Zero will be stored for OOB access

Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.

Implementations§

Source§

impl IGatherLayer

Source

pub fn setGatherAxis(self: Pin<&mut IGatherLayer>, axis: i32)

Set the axis used by GatherMode::kELEMENTS and GatherMode::kDEFAULT The axis must be less than the number of dimensions in the data input. The axis defaults to 0.

Undefined behavior when used with GatherMode::kND.

See [getGatherAxis()]

Source

pub fn getGatherAxis(self: &IGatherLayer) -> i32

Get the axis to gather on.

Undefined behavior when used with GatherMode::kND.

See [setGatherAxis()]

Source

pub fn setNbElementWiseDims(self: Pin<&mut IGatherLayer>, elementWiseDims: i32)

Set the number of leading dimensions of indices tensor to be handled elementwise.

The gathering of indexing starts from the dimension of data[NbElementWiseDims:]. The NbElementWiseDims must be less than the Rank of the data input.

  • elementWiseDims number of dims to be handled as elementwise.

Default: 0

The value of nbElementWiseDims and GatherMode are checked during network validation:

GatherMode::kDEFAULT: nbElementWiseDims can be 0 or 1. GatherMode::kND: nbElementWiseDims can be between 0 and one less than rank(data). GatherMode::kELEMENT: nbElementWiseDims must be 0

See [getNbElementWiseDims()]

Source

pub fn getNbElementWiseDims(self: &IGatherLayer) -> i32

Get the number of leading dimensions of indices tensor to be handled elementwise.

See [setNbElementWiseDims()]

Source

pub fn setMode(self: Pin<&mut IGatherLayer>, mode: GatherMode)

Set the gather mode.

See [getMode()]

Source

pub fn getMode(self: &IGatherLayer) -> GatherMode

Get the gather mode.

See [setMode()]

Trait Implementations§

Source§

impl AsLayer for IGatherLayer

Source§

fn as_layer(&self) -> &ILayer

Source§

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

Source§

impl AsLayerTyped for IGatherLayer

Source§

const TYPE: LayerType = LayerType::kGATHER

Source§

impl AsRef<ILayer> for IGatherLayer

Source§

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

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

impl ExternType for IGatherLayer

Source§

type Id = (n, v, i, n, f, e, r, _1, (), I, G, a, t, h, e, r, 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 IGatherLayer

Source§

unsafe fn allocate_uninitialized_cpp_storage() -> *mut IGatherLayer

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 IGatherLayer)

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.