Can I use a Variable object to index a tensor to get a loss from a loss matrix?

I have a torch tensor that stores different loss values depending on different outputs of my network.
I want to be able to index that tensor using my network output, which is a Variable object containing a FloatTensor.
Is this possible?
I can get the data out and convert to integer, but then the gradient won’t be calculable.
I have tried to index with but I get the following error:

IndexError: When performing advanced indexing the indexing objects must be LongTensors or convertible to LongTensors

Is there a way to get around this? Or any way to index with a Variable while still being able to calculate the gradient?
Thank you for your help!

Indexing results is never differentiable wrt the index.

Thanks again Simon :slight_smile: