MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / ArgMaxAtK

Method ArgMaxAtK

include/LightGBM/utils/array_args.h:136–151  ·  view source on GitHub ↗

Note: k refer to index here. e.g. k=0 means get the max number.

Source from the content-addressed store, hash-verified

134
135 // Note: k refer to index here. e.g. k=0 means get the max number.
136 inline static int ArgMaxAtK(std::vector<VAL_T>* arr, int start, int end, int k) {
137 if (start >= end - 1) {
138 return start;
139 }
140 int l = start;
141 int r = end - 1;
142 Partition(arr, start, end, &l, &r);
143 // if find or all elements are the same.
144 if ((k > l && k < r) || (l == start - 1 && r == end - 1)) {
145 return k;
146 } else if (k <= l) {
147 return ArgMaxAtK(arr, start, l + 1, k);
148 } else {
149 return ArgMaxAtK(arr, r, end, k);
150 }
151 }
152
153 // Note: k is 1-based here. e.g. k=3 means get the top-3 numbers.
154 inline static void MaxK(const std::vector<VAL_T>& array, int k, std::vector<VAL_T>* out) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected