Multiplying and powering python float and pytorch integer
Why does a python float multiplied by a torch.long gives a torch.float but powering a float by a torch.long gives a torch.long?

&gt;&gt;&gt; a = 0.9
&gt;&gt;&gt; b = torch.tensor(2, dtype=torch.long)

&gt;&gt;&gt; foo = a * b
&gt;&gt;&gt; print(foo, foo.dtype)
tensor(1.8000) torch.float32

&gt;&gt;&gt; bar = a ** b 
&gt;&gt;&gt; print(bar, bar.dtype)
tensor(0) torch.int64


This looks like a bug, probably in the way pytorch binds ** to __rpow__ or __pow__.

E.g. if you tried 0.9 - torch.tensor(2), since 0.9 isn't a tensor, this gets interpreted as torch.tensor(2).__rsub__(0.9), which works correctly. ** behaves the same way, but torch.tensor(2).__rpow__(0.9) incorrectly returns tensor(0) with dtype int64.

In the meantime you can use torch.tensor(0.9) ** torch.tensor(2).

Filed a bug:
https://github.com/pytorch/pytorch/issues/32436
