-
Notifications
You must be signed in to change notification settings - Fork 24.6k
[numpy] Add torch.nan_to_num #44592
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
Closed
kshitij12345
wants to merge
33
commits into
pytorch:master
from
kshitij12345:develop/numpy/nan_to_num
Closed
[numpy] Add torch.nan_to_num #44592
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f28d58b
add nan_to_num kernel impl
kshitij12345 1473c8a
Merge branch 'master' into develop/numpy/nan_to_num
kshitij12345 039001b
extra machinery for c10::Half support
kshitij12345 f2b4aba
add docs
kshitij12345 5ec18c5
update overrides.py
kshitij12345 90083ca
update signature
kshitij12345 9a0dcb4
support gradient
kshitij12345 c14529f
add test vs numpy
kshitij12345 d159a0d
rename pos_inf -> posinf, neg_inf -> neginf
kshitij12345 bab7127
Merge branch 'master' into develop/numpy/nan_to_num
kshitij12345 d9b2e59
remove merge stray
kshitij12345 cecd74a
update argument names
kshitij12345 0746035
address comment
kshitij12345 0a66921
replace randn < 0.2 -> rand < 0.2
kshitij12345 1345137
address comment
kshitij12345 6408886
address comment
kshitij12345 5f5af08
update UnaryUfuncInfo DB
kshitij12345 ed94f3c
Merge branch 'master' into develop/numpy/nan_to_num
kshitij12345 823bfa3
update types for nan_to_num
kshitij12345 e771f8a
try fixing docs warnings
kshitij12345 7df69bb
try fixing doc warnings
kshitij12345 f8fc57d
try fixing docs - esacpe `s`
kshitij12345 06b23e0
update gradient formula
kshitij12345 3dc297b
fix kernel name
kshitij12345 c260821
update docs
kshitij12345 a7ba1c9
replace dispatch for intergers with inplace copy_
kshitij12345 81258a9
kMerge branch 'develop/numpy/nan_to_num' into develop/numpy/nan_to_num
kshitij12345 d675bd7
move test to test_unary_funcs
kshitij12345 79428e4
Merge branch 'master' into develop/numpy/nan_to_num
kshitij12345 5288932
update kernel impl
kshitij12345 534f40b
remove unused _isfinite
kshitij12345 dffa5a9
address comment
kshitij12345 6141370
Merge branch 'master' into develop/numpy/nan_to_num
kshitij12345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -387,6 +387,41 @@ Tensor& logit_(Tensor& self, c10::optional<double> eps) { | |
return at::logit_out(self, self, eps); | ||
} | ||
|
||
Tensor& nan_to_num_out( | ||
Tensor& result, | ||
const Tensor& self, | ||
c10::optional<double> nan, | ||
c10::optional<double> pos_inf, | ||
c10::optional<double> neg_inf) { | ||
|
||
if (c10::isIntegralType(self.scalar_type())) { | ||
result.resize_as_(self); | ||
result.copy_(self); | ||
return result; | ||
} | ||
|
||
auto iter = TensorIterator::unary_op(result, self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @ezyang @anjali411 this is another case where we could consider returning self (for integer tensors) |
||
nan_to_num_stub(iter.device_type(), iter, nan, pos_inf, neg_inf); | ||
return result; | ||
} | ||
|
||
Tensor nan_to_num( | ||
const Tensor& self, | ||
c10::optional<double> nan, | ||
c10::optional<double> pos_inf, | ||
c10::optional<double> neg_inf) { | ||
auto result = at::empty_like(self); | ||
return at::nan_to_num_out(result, self, nan, pos_inf, neg_inf); | ||
} | ||
|
||
Tensor& nan_to_num_( | ||
Tensor& self, | ||
c10::optional<double> nan, | ||
c10::optional<double> pos_inf, | ||
c10::optional<double> neg_inf) { | ||
return at::nan_to_num_out(self, self, nan, pos_inf, neg_inf); | ||
} | ||
|
||
Tensor& tanh_out(Tensor& result, const Tensor& self) { return unary_op_impl_out(result, self, tanh_stub); } | ||
Tensor tanh(const Tensor& self) { return unary_op_impl(self, at::tanh_out); } | ||
Tensor& tanh_(Tensor& self) { return unary_op_impl_(self, at::tanh_out); } | ||
|
@@ -645,6 +680,7 @@ DEFINE_DISPATCH(log1p_stub); | |
DEFINE_DISPATCH(log2_stub); | ||
DEFINE_DISPATCH(logical_not_stub); | ||
DEFINE_DISPATCH(neg_stub); | ||
DEFINE_DISPATCH(nan_to_num_stub); | ||
DEFINE_DISPATCH(polygamma_stub); | ||
DEFINE_DISPATCH(reciprocal_stub); | ||
DEFINE_DISPATCH(round_stub); | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -312,6 +312,7 @@ Pointwise Ops | |
mul | ||
multiply | ||
mvlgamma | ||
nan_to_num | ||
neg | ||
negative | ||
nextafter | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.