If a
is some tensor and b
is a tensor or a number, is there a difference between torch.eq(a, b)
and a == b
?
If not, why does Pytorch API specify the torch.eq
method?
Should I avoid using the ==
operator and use torch.eq
instead?
I think both approaches should yield the same result:
a = torch.arange(10)
b = 2
print(a == b)
print(torch.eq(a, b))
b = torch.arange(10)
print(a == b)
print(torch.eq(a, b))
I guess:
- convenience if you prefer to use the explicit
torch.*
methods, e.g. such astorch.add
instead of+
- to allow users to pass the
out
tensor - I guess to map it easily to the internal
aten::eq
operator (but unsure if addingtorch.eq
actually makes it easier)
OK, I marked ptrblckās answer as solution. Maybe adding a small hint about the equivalence of ==
and torch.eq
would be something worth adding into the documentation?