In the autograd.py file, to implement tensor subtraction, a sub method is defined and set rsub = sub. When a tensor is subtracted from a scalar, it obviously results in the opposite of the expected result.
def __pow__(self, other):
if isinstance(other, Tensor):
return needle.ops.EWisePow()(self, other)
else:
return needle.ops.PowerScalar(other)(self)
def __sub__(self, other):
if isinstance(other, Tensor):
return needle.ops.EWiseAdd()(self, needle.ops.Negate()(other))
else:
return needle.ops.AddScalar(-other)(self)
__radd__ = __add__
__rmul__ = __mul__
__rsub__ = __sub__
__rmatmul__ = __matmul__