Torch.eq VS == (equality operator)

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 as torch.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 adding torch.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?