module onnxrt.ops_cpu.op_topk
#
Short summary#
module mlprodict.onnxrt.ops_cpu.op_topk
Runtime operator.
Classes#
class |
truncated documentation |
---|---|
Ths class hides a parameter used as a threshold above which the parallelisation is started: |
|
TopK ==== Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of shape [a_1, … |
|
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 |
---|---|
Retrieves the top-k elements. |
|
Retrieves the top-k elements using a C++ implementation when the axis is the last dimension, otherwise, it falls … |
Properties#
property |
truncated documentation |
---|---|
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of arguments as well as the list of parameters with the default values (close to the signature). … |
|
Returns the list of modified parameters. |
|
Returns the list of modified parameters. |
|
Returns the list of modified parameters. |
|
Returns the list of modified parameters. |
|
Returns the list of modified parameters. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns the list of optional arguments. |
|
Returns all parameters in a dictionary. |
|
Returns all parameters in a dictionary. |
|
Returns all parameters in a dictionary. |
|
Returns all parameters in a dictionary. |
|
Returns all parameters in a dictionary. |
Methods#
method |
truncated documentation |
---|---|
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
|
Runtime for operator TopK. The implementation is not the most efficient as it sorts everything then extracts … |
Documentation#
Runtime operator.
- 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.
- 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.
- 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.
- 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
.- __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.
- 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.
- 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