mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
C++ API parity: ELU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27028 Test Plan: Imported from OSS Differential Revision: D17682406 Pulled By: pbelevich fbshipit-source-id: 9c313237cb93b9870c6fcf8d01b3dbe4af4c6f2a
This commit is contained in:
committed by
Facebook Github Bot
parent
5005f7bce7
commit
c864454a8f
@@ -216,3 +216,23 @@ TEST_F(FunctionalTest, MaxUnpool2d) {
|
||||
{ 0, 46, 0, 48, 49}}}} , torch::kFloat)));
|
||||
ASSERT_EQ(y.sizes(), torch::IntArrayRef({2, 1, 5, 5}));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, ELU) {
|
||||
const auto size = 3;
|
||||
for (const auto inplace : {false, true}) {
|
||||
for (const auto alpha : {0.0, 0.42, 1.0, 4.2, 42.42}) {
|
||||
auto x = torch::linspace(-10.0, 10.0, size * size * size);
|
||||
x.resize_({size, size, size});
|
||||
auto y_exp = torch::max(torch::zeros_like(x), x) +
|
||||
torch::min(torch::zeros_like(x), alpha * (torch::exp(x) - 1.0));
|
||||
auto y = F::elu(x, ELUOptions().alpha(alpha).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