ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::rt::optimized_ops Namespace Reference

Data Structures

class  TopContainer
 class to define TopK operation More...
 

Functions

template<typename T >
void TopK (int32 row_size, int32 num_rows, const T *data, int32 k, int32 *output_indexes, T *output_values)
 Operates TopK operation with params.
 

Function Documentation

◆ TopK()

template<typename T >
void nnfw::rt::optimized_ops::TopK ( int32  row_size,
int32  num_rows,
const T *  data,
int32  k,
int32 output_indexes,
T *  output_values 
)

Operates TopK operation with params.

Parameters
[in]row_sizeSize of row in data
[in]num_rowsThe number of rows in data
[in]dataTo be operated in
[in]kThe top k predictions
[out]output_indexesIndexes of targets in the top k predictions
[out]output_valuesValues of targets in the top k predictions
Returns
N/A

Definition at line 163 of file topk_v2.h.

165{
166 TopContainer<T> topc(k, row_size);
167 for (int row = 0; row < num_rows; ++row)
168 {
169 const T *values_row = data + row * row_size;
170 topc.start_collecting(values_row);
171 for (int32 c = 0; c < row_size; ++c)
172 {
173 topc.push(c);
174 }
175
176 // Prepare output buffers.
177 int32 *indexes_row = output_indexes + row * k;
178 T *output_row = output_values + row * k;
179 // We always assume that the output is sorted.
180 const auto &top_k = topc.sorted_result();
181 std::copy(top_k.begin(), top_k.end(), indexes_row);
182 std::transform(top_k.begin(), top_k.end(), output_row,
183 [values_row](const int32 loc) { return values_row[loc]; });
184 }
185}
class to define TopK operation
Definition topk_v2.h:47
int32_t int32
Definition topk_v2.h:27

References nnfw::rt::optimized_ops::TopContainer< T >::push(), nnfw::rt::optimized_ops::TopContainer< T >::sorted_result(), and nnfw::rt::optimized_ops::TopContainer< T >::start_collecting().