Final aggregation function of argtopk Invoke argtopk one final time, sort the results internally, drop the data and return the index only.
(a_plus_idx, k, axis, keepdims)
| 244 | |
| 245 | |
| 246 | def argtopk_aggregate(a_plus_idx, k, axis, keepdims): |
| 247 | """Final aggregation function of argtopk |
| 248 | |
| 249 | Invoke argtopk one final time, sort the results internally, drop the data |
| 250 | and return the index only. |
| 251 | """ |
| 252 | assert keepdims is True |
| 253 | a_plus_idx = a_plus_idx if len(a_plus_idx) > 1 else a_plus_idx[0] |
| 254 | a, idx = argtopk(a_plus_idx, k, axis, keepdims) |
| 255 | axis = axis[0] |
| 256 | |
| 257 | idx2 = np.argsort(a, axis=axis) |
| 258 | idx = np.take_along_axis(idx, idx2, axis) |
| 259 | if k < 0: |
| 260 | return idx |
| 261 | return idx[ |
| 262 | tuple( |
| 263 | slice(None, None, -1) if i == axis else slice(None) for i in range(idx.ndim) |
| 264 | ) |
| 265 | ] |
| 266 | |
| 267 | |
| 268 | def arange(start, stop, step, length, dtype, like=None): |