module onnxrt.ops_cpu.op_topk#

Inheritance diagram of mlprodict.onnxrt.ops_cpu.op_topk

Short summary#

module mlprodict.onnxrt.ops_cpu.op_topk

Runtime operator.

source on GitHub

Classes#

class

truncated documentation

_CommonTopK

Ths class hides a parameter used as a threshold above which the parallelisation is started: th_para.

TopK_1

TopK_10

TopK_11

TopK ==== Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of shape [a_1, …

TopK_11

TopK ==== Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of shape [a_1, …

Functions#

function

truncated documentation

topk_sorted_implementation

Retrieves the top-k elements.

topk_sorted_implementation_cpp

Retrieves the top-k elements using a C++ implementation when the axis is the last dimension, otherwise, it falls …

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

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

args_default

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

args_default

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

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_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_default_modified

Returns the list of modified parameters.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_mandatory

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

args_optional

Returns the list of optional arguments.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

atts_value

Returns all parameters in a dictionary.

Methods#

method

truncated documentation

__init__

__init__

__init__

__init__

__init__

_common_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_common_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_common_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_common_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_common_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

_run

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts …

Documentation#

Runtime operator.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_topk.TopK#

alias of TopK_11

class mlprodict.onnxrt.ops_cpu.op_topk.TopK_1(onnx_node, desc=None, **options)#

Bases: _CommonTopK

__init__(onnx_node, desc=None, **options)#
_run(data, attributes=None, verbose=0, fLOG=None)#

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts the top k values.

Warning

ONNX specifications may be imprecise in case of negative value for axis. The implementation follows what onnxruntime does in top_k.cc.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_topk.TopK_10(onnx_node, desc=None, **options)#

Bases: _CommonTopK

__init__(onnx_node, desc=None, **options)#
_run(data, ink, attributes=None, verbose=0, fLOG=None)#

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts the top k values.

Warning

ONNX specifications may be imprecise in case of negative value for axis. The implementation follows what onnxruntime does in top_k.cc.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_topk.TopK_11(onnx_node, desc=None, **options)#

Bases: _CommonTopK

TopK#

Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of shape [a_1, a_2, …, a_n, r] and integer argument k, return two outputs:

-Value tensor of shape [a_1, a_2, …, a_{axis-1}, k, a_{axis+1}, … a_n]

which contains the values of the top k elements along the specified axis

-Index tensor of shape [a_1, a_2, …, a_{axis-1}, k, a_{axis+1}, … a_n] which

contains the indices of the top k elements (original indices from the input tensor).

If “largest” is 1 (the default value) then the k largest elements are returned. If “sorted” is 1 (the default value) then the resulting k elements will be sorted. If “sorted” is 0, order of returned ‘Values’ and ‘Indices’ are undefined.

Given two equivalent values, this operator uses the indices along the axis as

a tiebreaker. That is, the element with the lower index will appear first.

Attributes

  • axis: Dimension on which to do the sort. Negative value means counting dimensions from the back. Accepted range is [-r, r-1] where r = rank(input). Default value is nameaxisi-1typeINT (INT)

  • largest: Whether to return the top-K largest or smallest elements. Default value is namelargesti1typeINT (INT)

  • sorted: Whether to return the elements in sorted order. Default value is namesortedi1typeINT (INT)

Inputs

  • X (heterogeneous)T: Tensor of shape [a_1, a_2, …, a_n, r]

  • K (heterogeneous)tensor(int64): A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve

Outputs

  • Values (heterogeneous)T: Tensor of shape [a_1, a_2, …, a_{axis-1}, k, a_{axis+1}, … a_n] containing top K values from the input tensor

  • Indices (heterogeneous)I: Tensor of shape [a_1, a_2, …, a_{axis-1}, k, a_{axis+1}, … a_n] containing the corresponding input tensor indices for the top K values.

Type Constraints

  • T tensor(uint8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(int8), tensor(int16), tensor(int32), tensor(int64), tensor(float16), tensor(float), tensor(double): Constrain input and output types to numeric tensors.

  • I tensor(int64): Constrain index tensor to int64

Version

Onnx name: TopK

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

Runtime implementation: TopK

__init__(onnx_node, desc=None, **options)#
_run(data, ink, attributes=None, verbose=0, fLOG=None)#

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts the top k values.

Warning

ONNX specifications may be imprecise in case of negative value for axis. The implementation follows what onnxruntime does in top_k.cc.

source on GitHub

class mlprodict.onnxrt.ops_cpu.op_topk._CommonTopK(*args, **options)#

Bases: OpRun

Ths class hides a parameter used as a threshold above which the parallelisation is started: th_para.

source on GitHub

__init__(*args, **options)#
_common_run(data, ink, largest=1)#

Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts the top k values.

Warning

ONNX specifications may be imprecise in case of negative value for axis. The implementation follows what onnxruntime does in top_k.cc.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_topk.topk_sorted_implementation(X, k, axis, largest)#

Retrieves the top-k elements.

Parameters:
  • X – data

  • k – k in top-k

  • axis – axis chosen to select the top-k elements

  • largest – largest (1) or smallest (0)

Returns:

top-k values, top-k indices

See function _kneighbors_reduce_func.

source on GitHub

mlprodict.onnxrt.ops_cpu.op_topk.topk_sorted_implementation_cpp(X, k, axis, largest, th_para=50)#

Retrieves the top-k elements using a C++ implementation when the axis is the last dimension, otherwise, it falls back to topk_sorted_implementation.

Parameters:
  • X – data

  • k – k in top-k

  • axis – axis chosen to select the top-k elements

  • largest – largest (1) or smallest (0)

  • th_para – threshold for parallelisation

Returns:

top-k values, top-k indices

source on GitHub