module onnxrt.ops_cpu.op_gather_elements#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_gather_elements

Short summary#

module mlprodict.onnxrt.ops_cpu.op_gather_elements

Runtime operator.

source on GitHub

Classes#

class

truncated documentation

GatherElements

GatherElements ============== GatherElements takes two inputs data and indices of the same rank r >= 1 and an optional …

Functions#

function

truncated documentation

gather_numpy

Gathers values along an axis specified by dim. For a 3-D tensor the output is specified by:

gather_numpy_2

Properties#

property

truncated documentation

args_default

Returns the list of arguments as well as the list of parameters with the default values (close to the signature). …

args_default_modified

Returns the list of modified parameters.

args_mandatory

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

atts_value

Returns all parameters in a dictionary.

Methods#

method

truncated documentation

__init__

_infer_shapes

_infer_sizes

_infer_types

_run

to_python

Documentation#

Runtime operator.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_gather_elements.GatherElements(onnx_node, desc=None, **options)#

Bases: OpRun

GatherElements takes two inputs data and indices of the same rank r >= 1 and an optional attribute axis that identifies an axis of data (by default, the outer-most axis, that is axis 0). It is an indexing operation that produces its output by indexing into the input data tensor at index positions determined by elements of the indices tensor. Its output shape is the same as the shape of indices and consists of one value (gathered from the data) for each element in indices.

For instance, in the 3-D case (r = 3), the output produced is determined by the following equations: ``

out[i][j][k] = input[index[i][j][k]][j][k] if axis = 0, out[i][j][k] = input[i][index[i][j][k]][k] if axis = 1, out[i][j][k] = input[i][j][index[i][j][k]] if axis = 2,

``

This operator is also the inverse of ScatterElements. It is similar to Torch’s gather operation.

Example 1: ``

data = [

[1, 2], [3, 4],

] indices = [

[0, 0], [1, 0],

] axis = 1 output = [

[1, 1], [4, 3],

]

`` Example 2: ``

data = [

[1, 2, 3], [4, 5, 6], [7, 8, 9],

] indices = [

[1, 2, 0], [2, 0, 0],

] axis = 0 output = [

[4, 8, 3], [7, 2, 3],

]

``

Attributes

  • axis: 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 is nameaxisi0typeINT (INT)

Inputs

  • data (heterogeneous)T: Tensor of rank r >= 1.

  • indices (heterogeneous)Tind: Tensor of int32/int64 indices, with the same rank r as the input. 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.

Outputs

  • output (heterogeneous)T: Tensor of the same shape as indices.

Type Constraints

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

  • Tind tensor(int32), tensor(int64): Constrain indices to integer types

Version

Onnx name: GatherElements

This version of the operator has been available since version 13.

Runtime implementation: GatherElements

__init__(onnx_node, desc=None, **options)#
_infer_shapes(data, indices)#

Should be overwritten.

source on GitHub

_infer_sizes(*args)#

Should be overwritten.

source on GitHub

_infer_types(data, indices)#

Should be overwritten.

source on GitHub

_run(data, indices, attributes=None, verbose=0, fLOG=None)#

Should be overwritten.

source on GitHub

to_python(inputs)#

Returns a python code equivalent to this operator.

Parameters:

inputs – inputs name

Returns:

imports, python code, both as strings

source on GitHub

mlprodict.onnxrt.ops_cpu.op_gather_elements.gather_numpy(self, dim, index)#

Gathers values along an axis specified by dim. For a 3-D tensor the output is specified by:

out[i][j][k] = input[index[i][j][k]][j][k]  # if dim == 0
out[i][j][k] = input[i][index[i][j][k]][k]  # if dim == 1
out[i][j][k] = input[i][j][index[i][j][k]]  # if dim == 2
Parameters:
  • dim – The axis along which to index

  • index – A tensor of indices of elements to gather

Returns:

tensor of gathered values

See How to do scatter and gather operations in numpy?

source on GitHub