forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maskedtensor] add basic tests and unary/binary/reduction tests from …
…common_method_invocations (pytorch#82841) Decided offline on the invariant that: `masked_tensor` calls `MaskedTensor()`, which is analogous to `torch.tensor` `as_masked_tensor` calls `MaskedTensor._from_values()`, which is analogous to `torch.as_tensor` Pull Request resolved: pytorch#82841 Approved by: https://github.com/cpuhrsch, https://github.com/bhosmer
- Loading branch information
1 parent
2bc8216
commit 0c46e3e
Showing
10 changed files
with
449 additions
and
432 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .maskedtensor.core import is_masked_tensor, MaskedTensor | ||
from .maskedtensor.matmul import masked_bmm | ||
from .maskedtensor.creation import as_masked_tensor, masked_tensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates | ||
|
||
from .core import MaskedTensor, is_masked_tensor | ||
|
||
__all__ = [ | ||
"as_masked_tensor", | ||
"masked_tensor", | ||
] | ||
|
||
|
||
"""" | ||
These two factory functions are intended to mirror | ||
torch.tensor - guaranteed to be a leaf node | ||
torch.as_tensor - differentiable constructor that preserves the autograd history | ||
""" | ||
|
||
def masked_tensor(data, mask, requires_grad=False): | ||
assert not is_masked_tensor(data) | ||
assert not is_masked_tensor(mask) | ||
return MaskedTensor(data, mask, requires_grad) | ||
|
||
def as_masked_tensor(data, mask): | ||
assert not is_masked_tensor(data) | ||
assert not is_masked_tensor(mask) | ||
return MaskedTensor._from_values(data, mask) |
Oops, something went wrong.