Some funny behavior in numpy.float64.__mul__ when being multiplied with pytorch Variables. Reproduction code:
import torch
import numpy as np
scalar = np.array([1.1])[0] # is of type numpy.float64 rather than the primitive float
var = torch.autograd.Variable(torch.randn(2))
res1 = var * scalar
res2 = scalar * var
print(res2)
The verbatim result:
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Variable containing:
0.1395
[torch.FloatTensor of size 1]
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Variable containing:
1.0387
[torch.FloatTensor of size 1]
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
The output res1
is a torch.autograd.Variable while res2
is a numpy.array and res2[i][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0]
(31 zeros) is res1[i]
.