Getting indices of top-k/smallest-k elements of a Variable

It seems that torch topk and sort functions return both the indices and values for Tensor inputs, but they return only values for Variable inputs. When I look at the source code, the Topk function in autograd/_functions/ has an input parameter return_indices with default value False, but the topk function in autograd/ do not use this parameter when calling Topk.
Is there a reason for this? I need to get the indices of smallest k elements of a Variable. Is there a way to do this currently in pytorch?


1 Like

Ah, it is in fact a bug and we have to fix it. I’ve created an issue to track it.