Repository: pytorch/pytorch

Issue:
Comparison operators don't accept out typed as one of the inputs
[pytorch]
The docs say that for tensor comparison operators (gt,lt etc) it should be possible to pass out argument typed as input (https://pytorch.org/docs/master/torch.html?highlight=torch%20gt#torch.gt), yet when I try to do it, I hit an error
```
import torch
a=torch.randn(5,5)
b=torch.randn(5,5)
mask = torch.ByteTensor(a.size())
torch.gt(a,b,out=mask)#works
mask = torch.empty_like(a)
torch.gt(a,b,out=mask) #does not work

```
```
RuntimeError: Expected object of type torch.ByteTensor but found type torch.FloatTensor for argument #0 'result'
```
Should the docs be fixed, or is it a bug?


Discussion:
If it's really useful we can add it back; but we'll fix the docs for now

Resolving patch:
diff --git a/torch/_torch_docs.py b/torch/_torch_docs.py
--- a/torch/_torch_docs.py
+++ b/torch/_torch_docs.py
@@ -1332,7 +1332,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor. Must be a `ByteTensor` or the same type as `input`.
+    out (Tensor, optional): the output tensor. Must be a `ByteTensor`
 
 Returns:
     Tensor: A ``torch.ByteTensor`` containing a 1 at each location where comparison is true
@@ -1599,7 +1599,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor that must be a `ByteTensor` or the same type as :attr:`input`
+    out (Tensor, optional): the output tensor that must be a `ByteTensor`
 
 Returns:
     Tensor: A ``torch.ByteTensor`` containing a 1 at each location where comparison is true
@@ -1825,7 +1825,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor that must be a `ByteTensor` or the same type as :attr:`input`
+    out (Tensor, optional): the output tensor that must be a `ByteTensor`
 
 Returns:
     Tensor: A ``torch.ByteTensor`` containing a 1 at each location where comparison is true
@@ -1986,7 +1986,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor that must be a `ByteTensor` or the same type as :attr:`input`
+    out (Tensor, optional): the output tensor that must be a `ByteTensor`
 
 Returns:
     Tensor: A ``torch.ByteTensor`` containing a 1 at each location where comparison is true
@@ -2230,7 +2230,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor that must be a `ByteTensor` or the same type as :attr:`input`
+    out (Tensor, optional): the output tensor that must be a `ByteTensor`
 
 Returns:
     Tensor: A `torch.ByteTensor` containing a 1 at each location where comparison is true
@@ -2794,7 +2794,7 @@ def parse_kwargs(desc):
 Args:
     input (Tensor): the tensor to compare
     other (Tensor or float): the tensor or value to compare
-    out (Tensor, optional): the output tensor that must be a `ByteTensor` or the same type as `input`
+    out (Tensor, optional): the output tensor that must be a `ByteTensor`
 
 Returns:
     Tensor: A ``torch.ByteTensor`` containing a 1 at each location where comparison is true.


Test patch: