-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Labels
enhancementNot as big of a feature, but technically not a bug. Should be easy to fixNot as big of a feature, but technically not a bug. Should be easy to fixfeatureA request for a proper, new feature.A request for a proper, new feature.high prioritytriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Description
Currently if the the argument of __rmatmul__ is not a Tensor, PyTorch throws *** TypeError: matmul(): argument 'other' (position 1) must be Tensor, not Vec
Python data model asks that it return NotImplemented in such case. This allows interpreter to dispatch op to the proper implementation.
(ie see https://docs.python.org/3/library/numbers.html#implementing-the-arithmetic-operations)
Current behavior makes it hard to implement custom types. IE
class FactoredMatrix:
def __init__(self, mat):
self.mat = mat
def __matmul__(self, other):
return 0
def __rmatmul__(self, other):
return 1
x = torch.ones((2,2))
print(FactoredMatrix(x) @ x) # works
print(x @ FactoredMatrix(x)) # fails
colesbury
Metadata
Metadata
Assignees
Labels
enhancementNot as big of a feature, but technically not a bug. Should be easy to fixNot as big of a feature, but technically not a bug. Should be easy to fixfeatureA request for a proper, new feature.A request for a proper, new feature.high prioritytriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module