Elegant way to compare to torch.FloatTensor on GPU
I try to compare two torch.FloatTensor (with only one entry) lying on GPU like this:


  if (FloatTensor_A > FloatTensor_B): do something


The problem is, that (FloatTensor_A &gt; FloatTensor_B) gives ByteTensor back. Is there a way to do boolean comparison between these two scalar FloatTensors, without loading the tensors on CPU and converting them back to numpy or conventional floats?

The comparison operations in PyTorch return ByteTensors (see docs). In order to convert your result back to a float datatype, you can call .float() on your result. For example:

(t1 &gt; t2).float()


(t1 &gt; t2) will return a ByteTensor.

The inputs to the operation must be on the same memory (either CPU or GPU). The return result will be on the same memory. Of course, any Tensor can be moved to the respective memory by callin .cpu() or .cuda() on it.
