8000 Typing missing on arithmetic ops on `Tensor` · Issue #103393 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Typing missing on arithmetic ops on Tensor #103393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lkct opened this issue Jun 11, 2023 · 0 comments
Open

Typing missing on arithmetic ops on Tensor #103393

lkct opened this issue Jun 11, 2023 · 0 comments
Labels
module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@lkct
Copy link
Contributor
lkct commented Jun 11, 2023

🐛 Describe the bug

This is related to #103375 and #103376, but I assume it's better to split into smaller fixes.

Some of the dunder ops are not defined in _C._TensorBase but directly in Tensor:

pytorch/torch/_tensor.py

Lines 850 to 902 in 03101a2

@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rsub__(self, other):
return _C._VariableFunctions.rsub(self, other)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rdiv__(self, other):
return self.reciprocal() * other
__rtruediv__ = __rdiv__
__itruediv__ = _C._TensorBase.__idiv__
__pow__ = _handle_torch_function_and_wrap_type_error_to_not_implemented(
_C._TensorBase.pow
)
__ipow__ = _handle_torch_function_and_wrap_type_error_to_not_implemented(
_C._TensorBase.pow_
)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rmod__(self, other):
return torch.remainder(other, self)
def __format__(self, format_spec):
if has_torch_function_unary(self):
return handle_torch_function(Tensor.__format__, (self,), self, format_spec)
if self.dim() == 0 and not self.is_meta and type(self) is Tensor:
return self.item().__format__(format_spec)
return object.__format__(self, format_spec)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rpow__(self, other):
dtype = torch.result_type(other, self)
return torch.tensor(other, dtype=dtype, device=self.device) ** self
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __floordiv__(self, other):
return torch.floor_divide(self, other)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rfl 9218 oordiv__(self, other):
return torch.floor_divide(other, self)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rlshift__(self, other):
return torch.bitwise_left_shift(other, self)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rrshift__(self, other):
return torch.bitwise_right_shift(other, self)
@_handle_torch_function_and_wrap_type_error_to_not_implemented
def __rmatmul__(self, other):
return torch.matmul(other, self)

However, as seen, there's no typing for these methods.

Versions

master

cc @ezyang @malfet @rgommers @xuzhao9 @gramster

@malfet malfet added module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: typing Related to mypy type annotations triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0