Final aggregation function of topk Invoke topk one final time and then sort the results internally.
(a, k, axis, keepdims)
| 189 | |
| 190 | |
| 191 | def topk_aggregate(a, k, axis, keepdims): |
| 192 | """Final aggregation function of topk |
| 193 | |
| 194 | Invoke topk one final time and then sort the results internally. |
| 195 | """ |
| 196 | assert keepdims is True |
| 197 | a = topk(a, k, axis, keepdims) |
| 198 | axis = axis[0] |
| 199 | a = np.sort(a, axis=axis) |
| 200 | if k < 0: |
| 201 | return a |
| 202 | return a[ |
| 203 | tuple( |
| 204 | slice(None, None, -1) if i == axis else slice(None) for i in range(a.ndim) |
| 205 | ) |
| 206 | ] |
| 207 | |
| 208 | |
| 209 | def argtopk_preprocess(a, idx): |