8000 added documentation for masked_fill and masked_fill_ by julurisaichandu · Pull Request #149285 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions torch/_tensor_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,15 @@ def callable(a, b) -> number
Args:
mask (BoolTensor): the boolean mask
value (float): the value to fill in with

Example:
>>> self = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
>>> mask = torch.tensor([[0, 1, 0, 1, 0], [1, 0, 1, 0, 1]], dtype=torch.bool)
>>> self.masked_fill_(mask, -1)
>>> self
tensor([[ 1, -1, 3, -1, 5],
[-1, 7, -1, 9, -1]])

""",
)

Expand Down Expand Up @@ -6587,6 +6596,14 @@ def callable(a, b) -> number
masked_fill(mask, value) -> Tensor

Out-of-place version of :meth:`torch.Tensor.masked_fill_`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I think this page is intentionally left without docs to prevent duplication. (Here's a link to torch.Tensor.masked_fill_ for users)

Copy link
Author
@julurisaichandu julurisaichandu Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so @zeshengzong is the example for the masked_fill_ is valid? because the masked_fill don't have the example aswell


Example:
>>> self = torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
>>> mask = torch.tensor([[0, 1, 0, 1, 0], [1, 0, 1, 0, 1]], dtype=torch.bool)
>>> self.masked_fill(mask, -1)
tensor([[ 1, -1, 3, -1, 5],
[-1, 7, -1, 9, -1]])

""",
)

Expand Down
Loading
0