I saw that there is a median function supported. I am wondering whether there is any operation that can compute the k-largest values without using sorting? (I can implement it with topk() but I assume when k is large, the function is not very efficient?)

I am not sure to understand what you’re looking for? If you’re looking for the k-largest values, then `topk()`

is the function you should use, this is exactly what this function is doing.

I think it’d be neat to get just the kth largest value efficiently, eg the 0.25 and 0.75 quartile values, similar to np.percentile.

Best regards

Thomas

So you’re looking for the kth largest value? not all the top k largest values?

I’ve been looking for exactly that a few times. (And that is the similarity with median as far as I understand.)

No that does not exist as far as I know.

I know it’s not as efficient as it could be, but I implemented a pytorch version for percentile:

There now is a kthvalue function for CPU and CUDA in torch 1.1 (or the nightlies).

Best regards

Thomas

For those who later read this thread and want to jump to the docs, there are both a torch kthvalue method and a similar Tensor kthvalue method as well.

is there a simple way to have k be a vector rather than an int so that its a different k for each sample in a batch?