mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
C++ API parity: Threshold
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27538 Test Plan: Imported from OSS Differential Revision: D17835415 Pulled By: pbelevich fbshipit-source-id: 2a887704655be79ee458081c46a7eea31eca51dc
This commit is contained in:
committed by
Facebook Github Bot
parent
cbdd55c669
commit
446a79b959
@@ -787,3 +787,25 @@ TEST_F(FunctionalTest, Tanhshrink) {
|
||||
ASSERT_TRUE(torch::allclose(y, y_exp));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, Threshold) {
|
||||
const auto size = 3;
|
||||
for (const auto threshold : {0.5, 1.0, 2.0}) {
|
||||
for (const auto value : {0.5, 1.0, 2.0}) {
|
||||
for (const auto inplace : {false, true}) {
|
||||
auto x = torch::linspace(-3.0, 3.0, 61);
|
||||
x.resize_({size, size, size});
|
||||
auto y_exp = (x <= threshold) * value + (x > threshold) * x;
|
||||
auto y = F::threshold(x,
|
||||
ThresholdOptions(threshold, value).inplace(inplace));
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 3);
|
||||
ASSERT_EQ(y.sizes(), torch::IntArrayRef({size, size, size}));
|
||||
ASSERT_TRUE(torch::allclose(y, y_exp));
|
||||
if (inplace) {
|
||||
ASSERT_TRUE(torch::allclose(x, y_exp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user