Fix doc example of masked_scatter (#123664)

mask has to be a bool tensor

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123664
Approved by: https://github.com/peterbell10, https://github.com/albanD
This commit is contained in:
Isuru Fernando 2024-04-09 19:05:45 +00:00 committed by PyTorch MergeBot
parent adcfc2b582
commit d6fb1da806

View File

@ -3167,7 +3167,7 @@ Args:
Example:
>>> self = torch.tensor([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
>>> mask = torch.tensor([[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]])
>>> mask = torch.tensor([[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]], dtype=torch.bool)
>>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
>>> self.masked_scatter_(mask, source)
tensor([[0, 0, 0, 0, 1],
@ -6584,7 +6584,7 @@ Out-of-place version of :meth:`torch.Tensor.masked_scatter_`
Example:
>>> self = torch.tensor([0, 0, 0, 0, 0])
>>> mask = torch.tensor([[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]])
>>> mask = torch.tensor([[0, 0, 0, 1, 1], [1, 1, 0, 1, 1]], dtype=torch.bool)
>>> source = torch.tensor([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
>>> self.masked_scatter(mask, source)
tensor([[0, 0, 0, 0, 1],